# A few problems in saving a plot in 'eps' format

I tested saving in a ‘eps’ format function using the test code
from http://www.scipy.org/Cookbook/Matplotlib/LaTeX_Examples.

The code looks like



<details class='elided'>
<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>

#####################################################################

import pylab
from pylab import arange,pi,sin,cos,sqrt

fig_width_pt = 246.0  # Get this from LaTeX using \showthe\columnwidth
inches_per_pt = 1.0/72.27               # Convert pt to inch

golden_mean = (sqrt(5)-1.0)/2.0         # Aesthetic ratio

fig_width = fig_width_pt*inches_per_pt  # width in inches

fig_height = fig_width*golden_mean      # height in inches

fig_size =  [fig_width,fig_height]

params = {'backend': 'ps',

'axes.labelsize': 10,
'text.fontsize': 10,

'legend.fontsize': 10,
'xtick.labelsize': 8,

'ytick.labelsize': 8,
'text.usetex': True,

'figure.figsize': fig_size}
pylab.rcParams.update(params)

# Generate data
x = pylab.arange(-2*pi,2*pi,0.01)

y1 = sin(x)
y2 = cos(x)

# Plot data
pylab.figure(1)

pylab.clf()
pylab.axes([0.125,0.2,0.95-0.125,0.95-0.2])

pylab.plot(x,y1,'g:',label='$\sin(x)$')

pylab.plot(x,y2,'-b',label='$\cos(x)$')

pylab.xlabel('$x$ (radians)')

pylab.ylabel('$y$')

pylab.legend()
pylab.savefig('eps.eps')

pylab.savefig('png.png',dpi=200)

#####################################################################

After trying the above code, I found 2 problems in saving in 'eps' format.
I attached the result saved in eps format (eps.jpg) along with the result

saved in png format (png.png) to describe the problems.

1. The location of axes is not correct when the plot is saved in 'eps' format.
It seems like that the appointed axes location is ignored when any of the

component in the plot is out of the figure.
2. Although the legend label in the 'eps' file is acceptable, the legend
label in 'png' file looks better.



In addition to the above problems, I want to know whether there exists a way to

adjust the distance between a axis label and tick label. When I raised the axis
label font size to 11 or 12, the gap between a axis label and tick label becomes
too small. I may be able to put a text instead of axis label, it, however, takes too

much time for me to determine the proper text position manually everytime.
Actually I’ve asked the same question few days ago and I’ve not no answer so far.
Aren’t there any proper way to adjust the distance between a axis label and tick label?

Yong-Duk Jin

Hi Yong-Duk,

I tested saving in a 'eps' format function using the test code
from http://www.scipy.org/Cookbook/Matplotlib/LaTeX_Examples.

The code looks like

#####################################################################
import pylab
from pylab import arange,pi,sin,cos,sqrt
fig_width_pt = 246.0 # Get this from LaTeX using \showthe\columnwidth
inches_per_pt = 1.0/72.27 # Convert pt to inch
golden_mean = (sqrt(5)-1.0)/2.0 # Aesthetic ratio
fig_width = fig_width_pt*inches_per_pt # width in inches
fig_height = fig_width*golden_mean # height in inches
fig_size = [fig_width,fig_height]
params = {'backend': 'ps',
'axes.labelsize': 10,
'text.fontsize': 10,
'legend.fontsize': 10,
'xtick.labelsize': 8,
'ytick.labelsize': 8,
'text.usetex': True,
'figure.figsize': fig_size}
pylab.rcParams.update(params)
# Generate data
x = pylab.arange(-2*pi,2*pi,0.01)
y1 = sin(x)
y2 = cos(x)
# Plot data
pylab.figure(1)
pylab.clf()
pylab.axes([0.125,0.2,0.95-0.125,0.95-0.2])
pylab.plot(x,y1,'g:',label='$\sin(x)$')
pylab.plot(x,y2,'-b',label='$\cos(x)$')
pylab.xlabel('$x$ (radians)')
pylab.ylabel('$y$')
pylab.legend()
pylab.savefig('eps.eps')
pylab.savefig('png.png',dpi=200)
#####################################################################

After trying the above code, I found 2 problems in saving in 'eps' format.
I attached the result saved in eps format (eps.jpg) along with the result
saved in png format (png.png) to describe the problems.

1. The location of axes is not correct when the plot is saved in 'eps'
format. It seems like that the appointed axes location is ignored when any
of the component in the plot is out of the figure.

That is the result of an unfortunate workaround we have to use with the latex
backend. Briefly: the figure you are making is actually inserted into a latex
document, in order for latex to render the text. Latex yields a postscript
file, which does not include a bounding box. You want an eps file, with a
bounding box that preserves the placement of your axes in the visible window,
but the bbox is recalculated by ghostscript based on the contents of the
image. I don't know how to improve this, aside from switching to Jouni's

2. Although the legend label in the 'eps' file is acceptable, the legend
label in 'png' file looks better.

They look about the same to me, and I don't know what you mean by better. I
will say though, that there are better postscript viewers out there than the
one you are using. The tick labels in your eps example do not look as good as
they could. I see the same thing with kpdf, Adobe Reader does a better job of
rendering the text in our figures than does kpdf.

In addition to the above problems, I want to know whether there exists a
way to
adjust the distance between a axis label and tick label. When I raised the
axis
label font size to 11 or 12, the gap between a axis label and tick label
becomes
too small. I may be able to put a text instead of axis label, it, however,
takes too
much time for me to determine the proper text position manually everytime.
Actually I've asked the same question few days ago and I've not no answer
so far.
Aren't there any proper way to adjust the distance between a axis label and
tick label?

I don't know.

Darren

···

On Saturday 26 April 2008 08:26:33 am Yong-Duk Jin wrote: