|
From: mogliii <mo...@gm...> - 2011-08-18 16:30:01
Attachments:
Gridspec.svg
Gridspec.png
|
I could already answer one question by myself about the top margin in gridspec. '''1) I would like to reduce the top margin. For that I though I can do something like this: gs = gridspec.GridSpec(2, 1, width_ratios=[2,1]) - gs.update(bottom=0.2, left=0.2, hspace=0.05) + gs.update(bottom=0.2, left=0.2, hspace=0.05, top=0.1) But I get an error ""ValueError: bottom cannot be >= top"". This limitation is not clear to me, why is this so?''' So if I want a top margin of 0.1*figure height I would have to specify >>> top = 0.9 So "top" is the absolute distance of the top plot edge from the lower figure edge. 1.0 would make the plot extend to the top edge. Looking back I must say that http://matplotlib.sourceforge.net/api/gridspec_api.html#matplotlib.gridspec.GridSpecBase is not very helpful. And it is very counter-intuitive to the Axes dimension specification with location lower left and width/height >>> plt.axes([0.1, 0.1, 0.8, 0.8]) To clarify I created a small illustration. |
|
From: mogliii <mo...@gm...> - 2011-08-18 08:53:42
Attachments:
line_profiles.pdf
|
Hi, I want to have two plots above each other with shared y-axis. For this I am using gridspec to adjust the vertical distance between the graphs. Attached is a .pdf with the current results. Two problems: 1) I would like to reduce the top margin. For that I though I can do something like this: gs = gridspec.GridSpec(2, 1, width_ratios=[2,1]) - gs.update(bottom=0.2, left=0.2, hspace=0.05) + gs.update(bottom=0.2, left=0.2, hspace=0.05, top=0.1) But I get an error ""ValueError: bottom cannot be >= top"". This limitation is not clear to me, why is this so? 2) I want to make a shared y-axis label. I found this page: http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label But any additional axis I put before the gridspec axis is not shown in the end. Is there a special procedure that can be used together with gridspec? Below the code I use for the figure: ################################ import numpy as np import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec # Import data into numpy ndarray tung = np.loadtxt('tungsten_profiles_leveled.txt') insu = np.loadtxt('insulator_profiles_leveled.txt') fig_width_pt = 270 fig_height_pt = 220 inches_per_pt = 1.0/72.27 # Convert pt to inches fig_width = fig_width_pt*inches_per_pt # width in inches fig_height =fig_height_pt*inches_per_pt # height in inches fig_size = [fig_width,fig_height] # Settings for fitting LaTeX style plt.rc('font',**{'family':'serif','serif':['Computer Modern Roman']}) params = {'backend': 'ps', 'text.latex.preamble': [r"\usepackage{upgreek}"], 'axes.labelsize': 10, 'text.fontsize': 10, 'legend.fontsize': 8, 'xtick.labelsize': 8, 'ytick.labelsize': 8, 'text.usetex': True, 'figure.figsize': fig_size, 'axes.unicode_minus': True} plt.rcParams.update(params) ####### plt.figure(1) plt.clf() gs = gridspec.GridSpec(2, 1, width_ratios=[2,1]) gs.update(bottom=0.2, left=0.2, hspace=0.05, top=0.1) ax1 = plt.subplot(gs[0]) plt.ylabel(r'Height (nm)', labelpad = 12) for i in range(len(tung[:][0])/2): ax1.plot(tung[:,i*2]*1e6-0.3, tung[:,1+i*2]*1e9,linewidth=1) plt.ylim(-1,11) plt.yticks([0, 2, 4, 6, 8, 10]) leg = ax1.legend(('Profile 1', 'Profile 2', 'Profile 3', 'Profile 4', 'Profile 5', 'Profile 6', 'Profile 7'), shadow=True, loc = (1.1,-0.5)) plt.setp(ax1.get_xticklabels(), visible=False) ax1.annotate(r'\bf Tungsten', xy=(0,10), xycoords='data', # <-- check webpage for different coordinate systems horizontalalignment='left', verticalalignment='top', fontsize=10) ax2 = plt.subplot(gs[1], sharex = ax1) for i in range(len(insu[:][0])/2): ax2.plot(insu[:,i*2]*1e6-0.3, insu[:,1+i*2]*1e9,linewidth=1) plt.xlim(-0.1,2.1) plt.ylim(-1,11) plt.yticks([0, 2, 4, 6, 8, 10]) plt.xlabel(r'Position ($\upmu$m)', labelpad = 12) plt.ylabel(r'Height (nm)', labelpad = 12) # r for raw ax2.annotate(r'\bf Insulator', xy=(0,10), xycoords='data', # <-- check webpage for different coordinate systems horizontalalignment='left', verticalalignment='top', fontsize=10) #plt.show() plt.savefig('line_profiles.pdf') |
|
From: Jae-Joon L. <lee...@gm...> - 2011-08-23 04:08:59
|
On Thu, Aug 18, 2011 at 5:53 PM, mogliii <mo...@gm...> wrote: > 2) I want to make a shared y-axis label. I found this page: > http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label > But any additional axis I put before the gridspec axis is not shown in > the end. Is there a special procedure that can be used together with > gridspec? This is general behavior of subplot command. http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.subplot If you want to suppress this, do something like fig.add_subplot(gs[0]) Regards, -JJ |
|
From: Jae-Joon L. <lee...@gm...> - 2011-08-19 03:09:59
|
On Fri, Aug 19, 2011 at 1:29 AM, mogliii <mo...@gm...> wrote: > Looking back I must say that > http://matplotlib.sourceforge.net/api/gridspec_api.html#matplotlib.gridspec.GridSpecBase > is not very helpful. And it is very counter-intuitive to the Axes > dimension specification with location lower left and width/height > >>> plt.axes([0.1, 0.1, 0.8, 0.8]) Those parameters are inherited from subplot parameters http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.subplots_adjust But, I agree that the documentation of grispec needs to be improved (any contribution will be appreciated). Regards, -JJ |