... problem using tex on axes label...

Hi all,

following http://www.scipy.org/wikis/topical_software/UsingTex, and in particular the following example:

/from matplotlib import rc
from matplotlib.numerix import arange, cos, pi
from pylab import figure, axes, plot, xlabel, ylabel, title, \
     grid, savefig, show

rc('text', usetex=True)
figure(1)
ax = axes([0.15, 0.1, 0.8, 0.7])
t = arange(0.0, 1.0+0.01, 0.01)
s = cos(2*2*pi*t)+2
plot(t, s)

xlabel(r'\bf{time (s)}')
ylabel(r'\it{voltage (mV)}',fontsize=16)
title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
      fontsize=16, color='r')
savefig('tex_demo.eps')

show()
/
I obtain the following error:

[....]
File "/usr/lib/python2.3/site-packages/matplotlib/texmanager.py", line 296, in get_rgba
    X = readpng(pngfile)
RuntimeError: _image_module::readpng could not open PNG file /home/alex/.matplotlib/tex.cache/3d522deaf85577451c01974654b36ad3_270.png for reading

What does it means!?? I'm using matplotlib 0.83 on a linux box with tetex-3.0 and ghostscript-8.51 installed...

Thanks for the Help,

Alex.

Did you read the "common hangups" section at the end of the wiki? You have to
make sure that latex, and dvipng can be found on your PATH.

···

On Wednesday 03 August 2005 04:35 am, Alex Rada wrote:

Hi all,

following http://www.scipy.org/wikis/topical_software/UsingTex, and in
particular the following example:

/from matplotlib import rc
from matplotlib.numerix import arange, cos, pi
from pylab import figure, axes, plot, xlabel, ylabel, title, \
     grid, savefig, show

rc('text', usetex=True)
figure(1)
ax = axes([0.15, 0.1, 0.8, 0.7])
t = arange(0.0, 1.0+0.01, 0.01)
s = cos(2*2*pi*t)+2
plot(t, s)

xlabel(r'\bf{time (s)}')
ylabel(r'\it{voltage (mV)}',fontsize=16)
title(r"\TeX\ is Number
$\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
      fontsize=16, color='r')
savefig('tex_demo.eps')

show()
/
I obtain the following error:

[....]
File "/usr/lib/python2.3/site-packages/matplotlib/texmanager.py", line
296, in get_rgba
    X = readpng(pngfile)
RuntimeError: _image_module::readpng could not open PNG file
/home/alex/.matplotlib/tex.cache/3d522deaf85577451c01974654b36ad3_270.png
for reading

What does it means!?? I'm using matplotlib 0.83 on a linux box with
tetex-3.0 and ghostscript-8.51 installed...

--

Darren

The problem only occurs when you save the file in ps
or eps format. If instead png is used the error
doesn't appear, at least not at my machine!

Kristen

> Hi all,
>
> following

http://www.scipy.org/wikis/topical_software/UsingTex,

and in
> particular the following example:
>
> /from matplotlib import rc
> from matplotlib.numerix import arange, cos, pi
> from pylab import figure, axes, plot, xlabel,
ylabel, title, \
> grid, savefig, show
>
> rc('text', usetex=True)
> figure(1)
> ax = axes([0.15, 0.1, 0.8, 0.7])
> t = arange(0.0, 1.0+0.01, 0.01)
> s = cos(2*2*pi*t)+2
> plot(t, s)
>
> xlabel(r'\bf{time (s)}')
> ylabel(r'\it{voltage (mV)}',fontsize=16)
> title(r"\TeX\ is Number
>

$\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",

> fontsize=16, color='r')
> savefig('tex_demo.eps')
>
> show()
> /
> I obtain the following error:
>
> [....]
> File

"/usr/lib/python2.3/site-packages/matplotlib/texmanager.py",

line
> 296, in get_rgba
> X = readpng(pngfile)
> RuntimeError: _image_module::readpng could not
open PNG file
>

/home/alex/.matplotlib/tex.cache/3d522deaf85577451c01974654b36ad3_270.png

···

--- Darren Dale <dd55@...163...> wrote:

On Wednesday 03 August 2005 04:35 am, Alex Rada > wrote:
> for reading
>
> What does it means!?? I'm using matplotlib 0.83 on
a linux box with
> tetex-3.0 and ghostscript-8.51 installed...

Did you read the "common hangups" section at the end
of the wiki? You have to
make sure that latex, and dvipng can be found on
your PATH.

--

Darren

-------------------------------------------------------

SF.Net email is sponsored by: Discover Easy Linux
Migration Strategies
from IBM. Find simple to follow Roadmaps,
straightforward articles,
informative Webcasts and more! Get everything you
need to get up to
speed, fast.

http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs

I think I understand this. The problem is that the ghostscript command is
different on linux and windows. On Linux it is "gs", and on windows its
something like gs32win. Would you try editing your backend_ps.py file to read
the following, (but make sure gs32win is really the name of the executable),
note there are subtle changes throughout the block:

command = 'latex -interaction=nonstopmode "%s"' % texfile
stdin, stdout, stderr = os.popen3(command)
verbose.report(stdout.read(), 'debug-annoying')
verbose.report(stderr.read(), 'helpful')
command = 'dvips -R -T %fin,%fin -o "%s" "%s"' % (pw, ph, psfile, dvifile)
stdin, stdout, stderr = os.popen3(command)
verbose.report(stdout.read(), 'debug-annoying')
verbose.report(stderr.read(), 'helpful')
os.remove(epsfile)
if ext.startswith('.ep'):
    dpi = rcParams['ps.distiller.res']
    command = 'gs32win -dBATCH -dNOPAUSE -dSAFER -r%d \
                     -sDEVICE=epswrite -dLanguageLevel=2 -dEPSFitPage \
                     -sOutputFile="%s" "%s"'% (dpi, epsfile, psfile)
    stdin, stdout, stderr = os.popen3(command)
    verbose.report(stdout.read(), 'debug-annoying')
    verbose.report(stderr.read(), 'helpful')
    shutil.move(epsfile, outfile)
else: shutil.move(psfile, outfile)

At some point I'll come up with a way to automatically call the right command
for ghostscript, but I am really busy at the moment...

···

On Wednesday 03 August 2005 11:57 am, kristen kaasbjerg wrote:

The problem only occurs when you save the file in ps
or eps format. If instead png is used the error
doesn't appear, at least not at my machine!

--

Darren

Thanks.
Using the ghostscript executable gswin32c,
I can now produce beautiful EPS files.
Should I be able to see the same thing
in the TKAgg backend? (The LaTeX does
not show up; when running the example
http://www.scipy.org/wikis/topical_software/UsingTex
I see a red horizontal line for the title
and no labels on the axes.)

Thank you,
Alan Isaac

···

On Wed, 3 Aug 2005, Darren Dale apparently wrote:

Would you try editing your backend_ps.py file to read
the following, (but make sure gs32win is really the name of the executable),
note there are subtle changes throughout the block:

command = 'latex -interaction=nonstopmode "%s"' % texfile
stdin, stdout, stderr = os.popen3(command)
verbose.report(stdout.read(), 'debug-annoying')
verbose.report(stderr.read(), 'helpful')
command = 'dvips -R -T %fin,%fin -o "%s" "%s"' % (pw, ph, psfile, dvifile)
stdin, stdout, stderr = os.popen3(command)
verbose.report(stdout.read(), 'debug-annoying')
verbose.report(stderr.read(), 'helpful')
os.remove(epsfile)
if ext.startswith('.ep'):
    dpi = rcParams['ps.distiller.res']
    command = 'gs32win -dBATCH -dNOPAUSE -dSAFER -r%d \
                     -sDEVICE=epswrite -dLanguageLevel=2 -dEPSFitPage \
                     -sOutputFile="%s" "%s"'% (dpi, epsfile, psfile)
    stdin, stdout, stderr = os.popen3(command)
    verbose.report(stdout.read(), 'debug-annoying')
    verbose.report(stderr.read(), 'helpful')
    shutil.move(epsfile, outfile)
else: shutil.move(psfile, outfile)

Oh, thats great news, finally some success on windows! TeX should work across
the *Agg backends, but John did that work. Maybe he could comment.

···

On Saturday 06 August 2005 02:40 am, Alan G Isaac wrote:

On Wed, 3 Aug 2005, Darren Dale apparently wrote:
> Would you try editing your backend_ps.py file to read
> the following, (but make sure gs32win is really the name of the
> executable), note there are subtle changes throughout the block:
>
> command = 'latex -interaction=nonstopmode "%s"' % texfile
> stdin, stdout, stderr = os.popen3(command)
> verbose.report(stdout.read(), 'debug-annoying')
> verbose.report(stderr.read(), 'helpful')
> command = 'dvips -R -T %fin,%fin -o "%s" "%s"' % (pw, ph, psfile,
> dvifile) stdin, stdout, stderr = os.popen3(command)
> verbose.report(stdout.read(), 'debug-annoying')
> verbose.report(stderr.read(), 'helpful')
> os.remove(epsfile)
> if ext.startswith('.ep'):
> dpi = rcParams['ps.distiller.res']
> command = 'gs32win -dBATCH -dNOPAUSE -dSAFER -r%d \
> -sDEVICE=epswrite -dLanguageLevel=2 -dEPSFitPage \
> -sOutputFile="%s" "%s"'% (dpi, epsfile, psfile)
> stdin, stdout, stderr = os.popen3(command)
> verbose.report(stdout.read(), 'debug-annoying')
> verbose.report(stderr.read(), 'helpful')
> shutil.move(epsfile, outfile)
> else: shutil.move(psfile, outfile)

Thanks.
Using the ghostscript executable gswin32c,
I can now produce beautiful EPS files.
Should I be able to see the same thing
in the TKAgg backend? (The LaTeX does
not show up; when running the example
http://www.scipy.org/wikis/topical_software/UsingTex
I see a red horizontal line for the title
and no labels on the axes.)

--

Darren

Apologies if this posts twice:
I haven't seen it on the list.
Script and output below.
Pictures at http://nw08.american.edu/~aisaac/temp.htm

Cheers,
Alan Isaac

++++++++++++++++++++++ Script ++++++++++++++++++
#-*-coding:latin-1-*-
#see http://www.scipy.org/wikis/topical_software/UsingTex
from matplotlib import rc
from matplotlib.numerix import arange, cos, pi
from pylab import figure, axes, plot, xlabel, ylabel, title, \
   grid, savefig, show

rc('text', usetex=True)
t = arange(0.0, 1.0+0.01, 0.01)
s = cos(2*2*pi*t)+2

figure(1)
#works fine
ax = axes([0.15, 0.1, 0.8, 0.7])
plot(t, s)
xlabel(r'time ($s$)',fontsize=16)
ylabel(r'\it{voltage} ($m$)',fontsize=16)
title(r"\TeX\ is Number $\sum_{n=1}^\infty{-e^{i\pi}}/{2^n}$!",
    fontsize=16, color='r')
savefig('/temp1')

figure(2)
#use bold on ylabel -> missing text
ax = axes([0.15, 0.1, 0.8, 0.7])
plot(t, s)
xlabel(r'time ($s$)',fontsize=16)
ylabel(r'\bf{voltage} ($m$)',fontsize=16)
title(r"\TeX\ is Number $\sum_{n=1}^\infty{-e^{i\pi}}/{2^n}$!",
    fontsize=16, color='r')
savefig('/temp2')

figure(3)
#use \frac in title -> missing superscripts
ax = axes([0.15, 0.1, 0.8, 0.7])
plot(t, s)
xlabel(r'time ($s$)',fontsize=16)
ylabel(r'\it{voltage} ($m$)',fontsize=16)
title(r"\TeX\ is Number $\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
    fontsize=16, color='r')
savefig('/temp3')

figure(4)
# *add* \displaystyle in title -> missing title
ax = axes([0.15, 0.1, 0.8, 0.7])
plot(t, s)
xlabel(r'time ($s$)',fontsize=16)
ylabel(r'\it{voltage} ($m$)',fontsize=16)
title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
    fontsize=16, color='r')
savefig('/temp4')

show()

++++++++++++++++++++++ Script Output +++++++++++
FigureCanvasAgg.print_figure
FigureCanvasAgg.draw
RendererAgg.__init__
RendererAgg._get_agg_font
  findfont failed Lucida Grande
  findfont found Verdana, normal, normal 500, normal, 12.0
findfont returning C:\WINNT\Fonts\verdana.ttf
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
  findfont failed Lucida Grande
  findfont found Verdana, normal, normal 500, normal, 16.0
findfont returning C:\WINNT\Fonts\verdana.ttf
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
FigureCanvasAgg.print_figure
FigureCanvasAgg.draw
RendererAgg.__init__
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
FigureCanvasAgg.print_figure
FigureCanvasAgg.draw
RendererAgg.__init__
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
FigureCanvasAgg.print_figure
FigureCanvasAgg.draw
RendererAgg.__init__
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
FigureCanvasAgg.draw
RendererAgg.__init__
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
FigureCanvasAgg.draw
RendererAgg.__init__
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
FigureCanvasAgg.draw
RendererAgg.__init__
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
FigureCanvasAgg.draw
RendererAgg.__init__
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font

Again, sorry if this posts twice.

I have never created a patch before.
I'm just attaching the unified diff.
Let me know better ways to proceed.

Thank you,
Alan Isaac

============ DOCUMENTATION PATCH (texmanager.py) ===========
--- texmanager.py.orig Mon Aug 08 21:28:14 2005
+++ texmanager.py Mon Aug 08 21:39:21 2005
@@ -1,7 +1,7 @@
"""
This module supports embedded TeX expressions in matplotlib via dvipng
and dvips for the raster and postscript backends. The tex and
-dvipng/dvips information is cached in ~/.tex.cache for reuse between
+dvipng/dvips information is cached in ~/.matplotlib/tex.cache for reuse between
sessions

Requirements:
@@ -26,8 +26,10 @@
   Z = self.texmanager.get_rgba(s, size=12, dpi=80, rgb=(1,0,0))

To enable tex rendering of all text in your matplotlib figure, set
-text.usetex in your matplotlibrc file
-(http://matplotlib.sf.net/matplotlibrc)
+text.usetex in your matplotlibrc file (http://matplotlib.sf.net/matplotlibrc)
+or include these two lines in your script:
+from matplotlib import rc
+rc('text', usetex=True)

"""