matplotlib, usetex

B

Bill Jackson

Hi, I'm having some trouble plotting with the following matplotlibrc:

text.usetex : True

I tried clearing the cache files under ~/.matplotlib, but this did not
help the problem. I'd post on the matplotlib mailing list, but I have a
hard enough time browsing sourceforge's achives (frequent internal
server errors). Here is some output:


---- example.py ----
import pylab
pylab.plot(range(10))
pylab.show()
--------------------

# python example.py --verbose-helpful
matplotlib data path /usr/share/matplotlib/mpl-data
$HOME=/home/me
loaded rc file /home/me/matplotlibrc
matplotlib version 0.87.7
verbose.level helpful
interactive is False
platform is linux2
numerix Numeric 24.2
font search path ['/usr/share/matplotlib/mpl-data']
CONFIGDIR=/home/me/.matplotlib
loaded ttfcache file /home/me/.matplotlib/ttffont.cache
backend GTK version 2.10.4
Traceback (most recent call last):
File "example.py", line 2, in <module>
pylab.plot(range(10))
File "/usr/lib/python2.5/site-packages/matplotlib/pylab.py", line
2027, in plot
ret = gca().plot(*args, **kwargs)
File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line
2131, in plot
self.autoscale_view(scalex=scalex, scaley=scaley)
File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 985,
in autoscale_view
self.set_xlim(XL)
File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line
1227, in set_xlim
self.viewLim.intervalx().set_bounds(xmin, xmax)
TypeError: only length-1 arrays can be converted to Python scalars.


The problem does not exist when text.usetex is False. Ideas?
 
A

Alexander Schmolck

Bill Jackson said:
The problem does not exist when text.usetex is False. Ideas?

I have no idea whether this will resolve your problem, but you could try
updating to 0.90 (BTW what happens if you do axis([0,128,0,128])).

cheers,

'as
 
B

Bill Jackson

Alexander Schmolck wrote the following on 05/25/2007 02:33 PM:
(BTW what happens if you do axis([0,128,0,128])).

In [1]: import pylab

In [2]: pylab.axis([0,128,0,128])

In [3]: pylab.show()
---------------------------------------------------------------------------
<type 'exceptions.NotImplementedError'> Traceback (most recent call last)

/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py in
expose_event(self, widget, event)
282 x, y, w, h = self.allocation
283 self._pixmap_prepare (w, h)
--> 284 self._render_figure(self._pixmap, w, h)
285 self._need_redraw = False
286

/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py in
_render_figure(self, pixmap, width, height)
270 """
271 self._renderer.set_width_height (width, height)
--> 272 self.figure.draw (self._renderer)
273
274

/usr/lib/python2.5/site-packages/matplotlib/figure.py in draw(self,
renderer)
542
543 # render the axes
--> 544 for a in self.axes: a.draw(renderer)
545
546 # render the figure text

/usr/lib/python2.5/site-packages/matplotlib/axes.py in draw(self,
renderer, inframe)
1061
1062 for zorder, i, a in dsu:
-> 1063 a.draw(renderer)
1064
1065 self.transData.thaw() # release the lazy objects

/usr/lib/python2.5/site-packages/matplotlib/axis.py in draw(self,
renderer, *args, **kwargs)
559 tick.set_label1(label)
560 tick.set_label2(label)
--> 561 tick.draw(renderer)
562 if tick.label1On and tick.label1.get_visible():
563 extent = tick.label1.get_window_extent(renderer)

/usr/lib/python2.5/site-packages/matplotlib/axis.py in draw(self, renderer)
159 if self.tick2On: self.tick2line.draw(renderer)
160
--> 161 if self.label1On: self.label1.draw(renderer)
162 if self.label2On: self.label2.draw(renderer)
163

/usr/lib/python2.5/site-packages/matplotlib/text.py in draw(self, renderer)
836 def draw(self, renderer):
837 self.update_coords(renderer)
--> 838 Text.draw(self, renderer)
839 if self.get_dashlength() > 0.0:
840 self.dashline.draw(renderer)

/usr/lib/python2.5/site-packages/matplotlib/text.py in draw(self, renderer)
348
349 renderer.draw_tex(gc, x, y, line,
--> 350 self._fontproperties, angle)
351 return
352

/usr/lib/python2.5/site-packages/matplotlib/backend_bases.py in
draw_tex(self, gc, x, y, s, prop, angle, ismath)
379
380 def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
--> 381 raise NotImplementedError
382
383 def draw_text(self, gc, x, y, s, prop, angle, ismath=False):

<type 'exceptions.NotImplementedError'>:

In [4]:
 
B

Bill Jackson

Alexander Schmolck wrote the following on 05/25/2007 02:33 PM:
I have no idea whether this will resolve your problem, but you could try
updating to 0.90 (BTW what happens if you do axis([0,128,0,128])).

The problem appears to be with a matplotlibrc file. If I delete the
matplotlibrc file, then I am able to plot perfectly. Thus, it appears
that I am unable to specify usetex from my configuration file. Why is
this happening?

---- ~/.matplotlib/matplotlibrc ----
text.usetex : True

---- test.py ----
import matplotlib
import pylab
matplotlib.rc('text', usetex=True)
pylab.plot(range(10))
pylab.show()


Running 'python test.py' with the above matplotlibrc causes the errors
in my original post. Deleting matplotlibrc resolves the problem.
 
A

Alexander Schmolck

Bill Jackson said:
Alexander Schmolck wrote the following on 05/25/2007 02:33 PM:
I have no idea whether this will resolve your problem, but you could try
updating to 0.90 (BTW what happens if you do axis([0,128,0,128])).

The problem appears to be with a matplotlibrc file. If I delete the
matplotlibrc file, then I am able to plot perfectly. Thus, it appears that I
am unable to specify usetex from my configuration file. Why is this
happening?

---- ~/.matplotlib/matplotlibrc ----
text.usetex : True

---- test.py ----
import matplotlib
import pylab
matplotlib.rc('text', usetex=True)

I think it might be a good habit to develop to call ``rc`` before ``import
pylab`` -- some things won't take effect otherwise (this doesn't affect all
parameters and will likely be eventually fixed in general, but notably it does
currently affect some latex-related stuff, such as font choice).
pylab.plot(range(10))
pylab.show()


Running 'python test.py' with the above matplotlibrc causes the errors in my
original post. Deleting matplotlibrc resolves the problem.

I can't see any problem with you matplotlibrc; what happens if you swap around
the lines as I suggested above? Maybe it just appears to work, because the
usetex really does have no affect above, and you really are not using latex?

I have been using matplotlib with latex for fonts handling for some time now
(and I've even submitted a patch to ameliorate the rc problem mentioned
above), but the latex stuff has changed somewhat over time, and still has some
rough edges -- so for not immediately obvious problems with the latex handling
of an older version of matplotlib you're much more likely to find someone who
has the relevant details mentally available on the matplotlib-disc list are
much better than here; so I'd recommend you give it a try again (yeah sf is a
pain).

cheers,

'as
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top