making publication quality plots

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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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

···

On Sat, May 30, 2009 at 3:50 AM, Paul Anton Letnes <paul.anton.letnes@...287...> 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...

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.

···

On 30. mai. 2009, at 13.56, John Hunter wrote:

On Sat, May 30, 2009 at 3:50 AM, Paul Anton Letnes > <paul.anton.letnes@...287...> 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

#################
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.

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 <paul.anton.letnes@...287...> wrote:

On 30. mai. 2009, at 13.56, John Hunter wrote:

On Sat, May 30, 2009 at 3:50 AM, Paul Anton Letnes >> <paul.anton.letnes@...287...> 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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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

···

On Wed, Jun 3, 2009 at 2:11 AM, Paul Anton Letnes <paul.anton.letnes@...287...> wrote: