# Plotting for insertion into latex

Hi!

In some cases, I run matplotlib exclusively to put the generated pics in latex documents, and the crib is that the xlabel and ylabel and xtick and ytick font sizes are not big enough. The requirement is to make the fonts as big as the text size itself. I normally do not play around with dpi and figure size so much and hence was generating pics at 800 x 600 resolution and inserting them in latex with scaling to /textwidth (AFAIK… latex does not insert any image more than 480 pixels wide… I arrived at this figure by inserting two images one with \textwidth scaling and another with 0.6 scaling and observing that both were the same). This was making the fonts even smaller and rapidly varying parts of the graphs were getting poorly resolved… as in I see them as steps Zooming in on the PDF generated made them go away !!

Now changing the figure size to (2,1.5) and setting the dpi to 240… increased my linewidth and the fontsize of the xticks and yticks way too much…!! infact the xticks were so big that the entire font on the y axis did not even fit in the page !! However the image size was just perfect for insertion into latex !! So solving one problem gave me another one !!

Plotting at 800x600 with default dpi settings, with reduced xticks and yticks size and xlabel and ylabel font size solves one part of the problem, but the rapidly varying parts of the graph still seem to be broken in the inserted image.

So could anybody give me ideas on how to make publishable quality graphs with Matplotlib !!

bye !!

ganesh

···

Ganesh V
Department of Aerospace Engineering,

My homepage --> http://www.ae.iitm.ac.in/~ae03b007

Hi Ganesh,

I also use matplotlib mainly to create publication quality plots into
my latex documents. Here are the steps that I follow to achieve this:

1) Set figure size to 4 by 3 inches using:

figure (1, figsize=(4,3))
ax = subplot(111) # note that I will use ax below, that's why I
defined this line

2) Plot your data by using latex fonts. For this, you should have
usetex=True in your matplotlibrc file and also you should write labels
(or other text) inserting 'r' before them. Here is an example:

ylabel (r'Dynamic range \$(\log_{10})\$', fontsize=8)

3) Note that I also set the fontsize to 8, which gives a very nice
look in the final result as long as you don't scale your figure in
latex. To be consistent you should set all fontsizes to 8 point. For
example:

setp (ax.get_xticklabels(), fontsize=8)
setp (ax.get_yticklabels(), fontsize=8)

4) If necessary you can adjust the spacing around your plot using

with values according to your liking. Here I usually try to minimize
the redundant space around the plot area.

5) Most important: Do not resize your figures in latex. This messes up
all the font sizes and you will most likely suffer from unreadable
plots. As far as I know there is no practical limit on the size of a
figure you can insert into latex. Above we set the figure size to 4 by
3 inches, and this usually is a good measure since a letter size
document is 8.5 by 11 inches.

However, if you need bigger or small plots do it by changing the
figure size parameter in the matplotlib, do not do it in latex if you

I hope these will be helpful.

Cheers,
Oguz

···

On 12/4/06, Ganesh V <ganesh.iitm@...287...> wrote:

Hi!

In some cases, I run matplotlib exclusively to put the generated pics in
latex documents, and the crib is that the xlabel and ylabel and xtick and
ytick font sizes are not big enough. The requirement is to make the fonts as
big as the text size itself. I normally do not play around with dpi and
figure size so much and hence was generating pics at 800 x 600 resolution
and inserting them in latex with scaling to /textwidth (AFAIK.. latex does
not insert any image more than 480 pixels wide.. I arrived at this figure by
inserting two images one with \textwidth scaling and another with 0.6
scaling and observing that both were the same). This was making the fonts
even smaller and rapidly varying parts of the graphs were getting poorly
resolved.. as in I see them as steps Zooming in on the PDF generated made
them go away !!

Now changing the figure size to (2,1.5) and setting the dpi to 240..
increased my linewidth and the fontsize of the xticks and yticks way too
much..!! infact the xticks were so big that the entire font on the y axis
did not even fit in the page !! However the image size was just perfect for
insertion into latex !! So solving one problem gave me another one !!

Plotting at 800x600 with default dpi settings, with reduced xticks and
yticks size and xlabel and ylabel font size solves one part of the problem,
but the rapidly varying parts of the graph still seem to be broken in the
inserted image.

So could anybody give me ideas on how to make publishable quality graphs
with Matplotlib !!

bye !!

ganesh

--
Ganesh V
Department of Aerospace Engineering,