Re: [Matplotlib-users] making publication quality plots From: Paul Anton Letnes - 2009-06-03 06:11 ```On 30. mai. 2009, at 13.56, John Hunter wrote: > On Sat, May 30, 2009 at 3:50 AM, Paul Anton Letnes > wrote: >> Hello again, >> >> >> I can set the figure size and font size, that all works fine. >> However, >> the legend is prohibitively large: for a plot 3 inches wide (why >> doesn't matplotlib use centimeters or similar?), the legend takes up >> about one third of the plot. This does not look too good... > > Please post a complete example. As for inches vs cm, that is my fault > -- I can't remember if it was for matlab compatibility, or due to my > provincial ways this side of the pond. > > JDH Hi, This is my function which does the plotting. The "coeffarr" is a 2D array (function uses 7 first columns) with first column being frequencies, other columns being real/imag part of whatever I'm plotting. ################# import matplotlib matplotlib.use('ps') import pylab def plot(coeffarr): 'Do the actual plotting.' nfreqs, ncoeffs = coeffarr.shape legends = [] for i in range(1, 6, 2): # real part columns pylab.plot(coeffarr[:,0], coeffarr[:,i], RE_STYLE) legends.append('l = %i' % int((i + 1) / 2)) pylab.plot(coeffarr[:,0], coeffarr[:,i+1], IM_STYLE) legends.append('l = %i' % int((i + 1) / 2)) pylab.legend(legends) pylab.xlabel('Frequency [eV]') pylab.ylabel('\$A_{lm}R^{-l-1}\$') pylab.savefig(PLOTFILE) #################### My matplotlibrc file is essentially this: #################### backend : MacOSX # added by paulanto on 16. feb. 08 numerix : numpy # numpy, Numeric or numarray lines.linewidth : 1.0 # line width in points font.family : serif font.size : 10.0 text.usetex : True axes.linewidth : 1.0 # edge linewidth legend.fontsize : 10.0 figure.figsize : 3.0, 2.3 # figure size in inches #################### Is this complete enough? If you do the plot, you'll see that the plot is about one column wide (7 cm-ish) and that the legend is relatively large. I made similar size plots in Gnuplot before, at font size 10, but the legend was somehow less dominant. Also, will it help getting rid of the rectangle? cheers, Paul. ```

[Matplotlib-users] making publication quality plots Paul Anton Letnes <paul.letnes@gm...>
 Re: [Matplotlib-users] making publication quality plots From: Chaitanya Krishna - 2009-05-29 15:39 ```Hi, I usually fix the size of the figure when I produce it. I use rcparams below for a single column plot. This usually solves the problem. What you see is what you get in the final document if you use the same size of the figure as used to produce it. def paper_single(): plt.rc('figure', figsize=(3.375,3.375)) plt.rc('figure.subplot', left=0.15, right=0.97, bottom=0.1, top=0.95) plt.rc('lines', linewidth=1.5) plt.rc('font', size=10.0) plt.rc('xtick', labelsize='small') plt.rc('ytick', labelsize='small') plt.rc('legend', fontsize='medium') Cheers, Chaitanya On Fri, May 29, 2009 at 5:25 PM, Paul Anton Letnes wrote: > Howdy y'all! > > I'm trying to make a publication quality plot for a two-column latex > article. I'm using latex for text processing, so the plot quality > itself is impeccable. However, as I scale the plot size down, the > legend becomes extremely large compared to the plot itself.  Has > anyone solved this problem in a good manner? I'm not willing to make > do without the legend. > > cheers, > Paul. > > > ------------------------------------------------------------------------------ > Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT > is a gathering of tech-side developers & brand creativity professionals. Meet > the minds behind Google Creative Lab, Visual Complexity, Processing, & > iPhoneDevCamp as they present alongside digital heavyweights like Barbarian > Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ```

 Re: [Matplotlib-users] making publication quality plots From: John Hunter - 2009-05-29 16:15 ```On Fri, May 29, 2009 at 10:25 AM, Paul Anton Letnes wrote: > I'm trying to make a publication quality plot for a two-column latex > article. I'm using latex for text processing, so the plot quality > itself is impeccable. However, as I scale the plot size down, the > legend becomes extremely large compared to the plot itself. Has > anyone solved this problem in a good manner? I'm not willing to make > do without the legend. The major determinant of the legend is the fontsize, so if you want to make a small figure in inches, you may want to make the legend font smaller import matplotlib.font_manager as font_manager leg = ax.legend(loc='upper left', prop=font_manager.FontProperties(size=10)) JDH ```

 Re: [Matplotlib-users] making publication quality plots From: Paul Anton Letnes - 2009-05-30 08:51 ```Hello again, I can set the figure size and font size, that all works fine. However, the legend is prohibitively large: for a plot 3 inches wide (why doesn't matplotlib use centimeters or similar?), the legend takes up about one third of the plot. This does not look too good... cheers, Paul On 29. mai. 2009, at 17.38, Damon McDougall wrote: > Hi Paul, > > You could set the figure size and font size in inches of your plot > in matplotlib to be the same as that of the physical size it will > appear on paper. That way, all your axes labels and plot text will > be the same size as the text in your latex document. > > Is this what you want? > Regards, > --Damon > > On 29 May 2009, at 16:25, Paul Anton Letnes wrote: > >> Howdy y'all! >> >> I'm trying to make a publication quality plot for a two-column latex >> article. I'm using latex for text processing, so the plot quality >> itself is impeccable. However, as I scale the plot size down, the >> legend becomes extremely large compared to the plot itself. Has >> anyone solved this problem in a good manner? I'm not willing to make >> do without the legend. >> >> cheers, >> Paul. >> >> >> ------------------------------------------------------------------------------ >> Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT >> is a gathering of tech-side developers & brand creativity >> professionals. Meet >> the minds behind Google Creative Lab, Visual Complexity, >> Processing, & >> iPhoneDevCamp as they present alongside digital heavyweights like >> Barbarian >> Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users@... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ```

 Re: [Matplotlib-users] making publication quality plots From: John Hunter - 2009-05-30 11:57 ```On Sat, May 30, 2009 at 3:50 AM, Paul Anton Letnes wrote: > Hello again, > > > I can set the figure size and font size, that all works fine. However, > the legend is prohibitively large: for a plot 3 inches wide (why > doesn't matplotlib use centimeters or similar?), the legend takes up > about one third of the plot. This does not look too good... Please post a complete example. As for inches vs cm, that is my fault -- I can't remember if it was for matlab compatibility, or due to my provincial ways this side of the pond. JDH ```

 Re: [Matplotlib-users] making publication quality plots From: Paul Anton Letnes - 2009-06-03 06:11 ```On 30. mai. 2009, at 13.56, John Hunter wrote: > On Sat, May 30, 2009 at 3:50 AM, Paul Anton Letnes > wrote: >> Hello again, >> >> >> I can set the figure size and font size, that all works fine. >> However, >> the legend is prohibitively large: for a plot 3 inches wide (why >> doesn't matplotlib use centimeters or similar?), the legend takes up >> about one third of the plot. This does not look too good... > > Please post a complete example. As for inches vs cm, that is my fault > -- I can't remember if it was for matlab compatibility, or due to my > provincial ways this side of the pond. > > JDH Hi, This is my function which does the plotting. The "coeffarr" is a 2D array (function uses 7 first columns) with first column being frequencies, other columns being real/imag part of whatever I'm plotting. ################# import matplotlib matplotlib.use('ps') import pylab def plot(coeffarr): 'Do the actual plotting.' nfreqs, ncoeffs = coeffarr.shape legends = [] for i in range(1, 6, 2): # real part columns pylab.plot(coeffarr[:,0], coeffarr[:,i], RE_STYLE) legends.append('l = %i' % int((i + 1) / 2)) pylab.plot(coeffarr[:,0], coeffarr[:,i+1], IM_STYLE) legends.append('l = %i' % int((i + 1) / 2)) pylab.legend(legends) pylab.xlabel('Frequency [eV]') pylab.ylabel('\$A_{lm}R^{-l-1}\$') pylab.savefig(PLOTFILE) #################### My matplotlibrc file is essentially this: #################### backend : MacOSX # added by paulanto on 16. feb. 08 numerix : numpy # numpy, Numeric or numarray lines.linewidth : 1.0 # line width in points font.family : serif font.size : 10.0 text.usetex : True axes.linewidth : 1.0 # edge linewidth legend.fontsize : 10.0 figure.figsize : 3.0, 2.3 # figure size in inches #################### Is this complete enough? If you do the plot, you'll see that the plot is about one column wide (7 cm-ish) and that the legend is relatively large. I made similar size plots in Gnuplot before, at font size 10, but the legend was somehow less dominant. Also, will it help getting rid of the rectangle? cheers, Paul. ```

 Re: [Matplotlib-users] making publication quality plots From: Chaitanya Krishna - 2009-06-03 06:26 ```Hi Paul, Can you try font.size: 10 legend.fontsize: small [or medium] in your rc file. Defining the fontsize and then defining the fontsize of the xtick labels, legend etc with respect to this font size seems to work better than defining everything by hand. Switching off the legend frame does seem to save some place. You can use pylab.legend('your legend').draw_frame(False) Cheers, Chaitanya On Wed, Jun 3, 2009 at 8:11 AM, Paul Anton Letnes wrote: > On 30. mai. 2009, at 13.56, John Hunter wrote: > >> On Sat, May 30, 2009 at 3:50 AM, Paul Anton Letnes >> wrote: >>> Hello again, >>> >>> >>> I can set the figure size and font size, that all works fine. >>> However, >>> the legend is prohibitively large: for a plot 3 inches wide (why >>> doesn't matplotlib use centimeters or similar?), the legend takes up >>> about one third of the plot. This does not look too good... >> >> Please post a complete example.  As for inches vs cm, that is my fault >> --  I can't remember if it was for matlab compatibility, or due to my >> provincial ways this side of the pond. >> >> JDH > > Hi, > > This is my function which does the plotting. The "coeffarr" is a 2D > array (function uses 7 first columns) with first column being > frequencies, other columns being real/imag part of whatever I'm > plotting. > ################# > import matplotlib > matplotlib.use('ps') > import pylab > def plot(coeffarr): >     'Do the actual plotting.' >     nfreqs, ncoeffs = coeffarr.shape >     legends = [] >     for i in range(1, 6, 2): # real part columns >         pylab.plot(coeffarr[:,0], coeffarr[:,i], RE_STYLE) >         legends.append('l = %i' % int((i + 1) / 2)) >         pylab.plot(coeffarr[:,0], coeffarr[:,i+1], IM_STYLE) >         legends.append('l = %i' % int((i + 1) / 2)) >     pylab.legend(legends) >     pylab.xlabel('Frequency [eV]') >     pylab.ylabel('\$A_{lm}R^{-l-1}\$') >     pylab.savefig(PLOTFILE) > #################### > My matplotlibrc file is essentially this: > #################### > backend       : MacOSX # added by paulanto on 16. feb. 08 > numerix      : numpy  # numpy, Numeric or numarray > lines.linewidth   : 1.0     # line width in points > font.family         : serif > font.size           : 10.0 > text.usetex         : True > axes.linewidth      : 1.0     # edge linewidth > legend.fontsize      : 10.0 > figure.figsize   : 3.0, 2.3    # figure size in inches > #################### > > Is this complete enough? If you do the plot, you'll see that the plot > is about one column wide (7 cm-ish) and that the legend is relatively > large. I made similar size plots in Gnuplot before, at font size 10, > but the legend was somehow less dominant. > > Also, will it help getting rid of the rectangle? > > > cheers, > Paul. > > > ------------------------------------------------------------------------------ > OpenSolaris 2009.06 is a cutting edge operating system for enterprises > looking to deploy the next generation of Solaris that includes the latest > innovations from Sun and the OpenSource community. Download a copy and > enjoy capabilities such as Networking, Storage and Virtualization. > Go to: http://p.sf.net/sfu/opensolaris-get > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ```

 Re: [Matplotlib-users] making publication quality plots From: Jae-Joon Lee - 2009-06-03 10:00 ```On Wed, Jun 3, 2009 at 2:11 AM, Paul Anton Letnes wrote: > Is this complete enough? If you do the plot, you'll see that the plot Unfortunately not. It is best if you post a stand-alone script that we can simply run with copy-and-paste. > is about one column wide (7 cm-ish) and that the legend is relatively > large. I made similar size plots in Gnuplot before, at font size 10, > but the legend was somehow less dominant. Please be more specific why you think the legend looks large, e.g., too much line-spacing, too long handle length, too much padding, etc. I think the legend has an adequate size in my view, even with your configuration. You may post the output of gnuplot and compare it with the output of matplotlib. Also, let us know what version of mpl you're using. The legend function has recently undergone some changes. You can customize most of spacing parameters of the legend. Take a look at the documentation. http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.legend The default figure size is 8 inch x 6 inch, and most of other parameters are tuned for this setup. And some of these default parameters won't work well if you simply create a figure of very small size. My personal approach is to create a figure with a default size (or some slight adjustment) and do not worry about other parameters, and simply scale down the output eps file itself when I include it in the latex document. Regards, -JJ ```

 [Matplotlib-users] Fwd: making publication quality plots From: Paul Anton Letnes - 2009-06-05 09:56 ```Hi Chaitanya (and everyone else), thanks for some nice advice! The font and legend frame tips worked quite well. I would appreciate it if it was possible to remove the legend frame by default, i.e. in the matplotlibrc file, if possible. In my opinion, this frame clutters the plot unnecessarily; I rarely see such frames in publications. Thanks! Paul. Begin forwarded message: > From: Chaitanya Krishna > Date: 3. juni 2009 08.26.07 GMT+02:00 > To: Paul Anton Letnes > Cc: matplotlib-users@... > Subject: Re: [Matplotlib-users] making publication quality plots > > Hi Paul, > > Can you try > font.size: 10 > legend.fontsize: small [or medium] in your rc file. > > Defining the fontsize and then defining the fontsize of the xtick > labels, legend etc with respect to this font size seems to work better > than defining everything by hand. > > Switching off the legend frame does seem to save some place. You can > use pylab.legend('your legend').draw_frame(False) > > Cheers, > Chaitanya > > On Wed, Jun 3, 2009 at 8:11 AM, Paul Anton Letnes > wrote: >> On 30. mai. 2009, at 13.56, John Hunter wrote: >> >>> On Sat, May 30, 2009 at 3:50 AM, Paul Anton Letnes >>> wrote: >>>> Hello again, >>>> >>>> >>>> I can set the figure size and font size, that all works fine. >>>> However, >>>> the legend is prohibitively large: for a plot 3 inches wide (why >>>> doesn't matplotlib use centimeters or similar?), the legend takes >>>> up >>>> about one third of the plot. This does not look too good... >>> >>> Please post a complete example. As for inches vs cm, that is my >>> fault >>> -- I can't remember if it was for matlab compatibility, or due to >>> my >>> provincial ways this side of the pond. >>> >>> JDH >> >> Hi, >> >> This is my function which does the plotting. The "coeffarr" is a 2D >> array (function uses 7 first columns) with first column being >> frequencies, other columns being real/imag part of whatever I'm >> plotting. >> ################# >> import matplotlib >> matplotlib.use('ps') >> import pylab >> def plot(coeffarr): >> 'Do the actual plotting.' >> nfreqs, ncoeffs = coeffarr.shape >> legends = [] >> for i in range(1, 6, 2): # real part columns >> pylab.plot(coeffarr[:,0], coeffarr[:,i], RE_STYLE) >> legends.append('l = %i' % int((i + 1) / 2)) >> pylab.plot(coeffarr[:,0], coeffarr[:,i+1], IM_STYLE) >> legends.append('l = %i' % int((i + 1) / 2)) >> pylab.legend(legends) >> pylab.xlabel('Frequency [eV]') >> pylab.ylabel('\$A_{lm}R^{-l-1}\$') >> pylab.savefig(PLOTFILE) >> #################### >> My matplotlibrc file is essentially this: >> #################### >> backend : MacOSX # added by paulanto on 16. feb. 08 >> numerix : numpy # numpy, Numeric or numarray >> lines.linewidth : 1.0 # line width in points >> font.family : serif >> font.size : 10.0 >> text.usetex : True >> axes.linewidth : 1.0 # edge linewidth >> legend.fontsize : 10.0 >> figure.figsize : 3.0, 2.3 # figure size in inches >> #################### >> >> Is this complete enough? If you do the plot, you'll see that the plot >> is about one column wide (7 cm-ish) and that the legend is relatively >> large. I made similar size plots in Gnuplot before, at font size 10, >> but the legend was somehow less dominant. >> >> Also, will it help getting rid of the rectangle? >> >> >> cheers, >> Paul. >> >> >> ------------------------------------------------------------------------------ >> OpenSolaris 2009.06 is a cutting edge operating system for >> enterprises >> looking to deploy the next generation of Solaris that includes the >> latest >> innovations from Sun and the OpenSource community. Download a copy >> and >> enjoy capabilities such as Networking, Storage and Virtualization. >> Go to: http://p.sf.net/sfu/opensolaris-get >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users@... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> ```

 Re: [Matplotlib-users] Fwd: making publication quality plots From: John Hunter - 2009-06-05 11:22 ```On Fri, Jun 5, 2009 at 4:56 AM, Paul Anton Letnes wrote: > Hi Chaitanya (and everyone else), > > > thanks for some nice advice! The font and legend frame tips worked > quite well. > > I would appreciate it if it was possible to remove the legend frame by > default, i.e. in the matplotlibrc file, if possible. In my opinion, > this frame clutters the plot unnecessarily; I rarely see such frames > in publications. I frequently make the frame semi-transparent, though this won't work for EPS leg = ax.legend(...) lege.get_frame().set_alpha(0.5) Some rc default for the legend frame (on/off, alpha) would be useful. JDH ```