matplotlib, usetex

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Jackson

    #1

    matplotlib, usetex

    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(rang e(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(rang e(10))
    File "/usr/lib/python2.5/site-packages/matplotlib/pylab.py", line
    2027, in plot
    ret = gca().plot(*arg s, **kwargs)
    File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line
    2131, in plot
    self.autoscale_ view(scalex=sca lex, scaley=scaley)
    File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 985,
    in autoscale_view
    self.set_xlim(X L)
    File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line
    1227, in set_xlim
    self.viewLim.in tervalx().set_b ounds(xmin, xmax)
    TypeError: only length-1 arrays can be converted to Python scalars.


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

  • Alexander Schmolck

    #2
    Re: matplotlib, usetex

    Bill Jackson <jackson@hotmai l.comwrites:
    >
    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

    Comment

    • Bill Jackson

      #3
      Re: matplotlib, usetex

      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.Not ImplementedErro r' Traceback (most recent call last)

      /usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py in
      expose_event(se lf, widget, event)
      282 x, y, w, h = self.allocation
      283 self._pixmap_pr epare (w, h)
      --284 self._render_fi gure(self._pixm ap, w, h)
      285 self._need_redr aw = 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_heigh t (width, height)
      --272 self.figure.dra w (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(rende rer)
      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.dra w(renderer)
      162 if self.label2On: self.label2.dra w(renderer)
      163

      /usr/lib/python2.5/site-packages/matplotlib/text.py in draw(self, renderer)
      836 def draw(self, renderer):
      837 self.update_coo rds(renderer)
      --838 Text.draw(self, renderer)
      839 if self.get_dashle ngth() 0.0:
      840 self.dashline.d raw(renderer)

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

      /usr/lib/python2.5/site-packages/matplotlib/backend_bases.p y 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 NotImplementedE rror
      382
      383 def draw_text(self, gc, x, y, s, prop, angle, ismath=False):

      <type 'exceptions.Not ImplementedErro r'>:

      In [4]:

      Comment

      • Bill Jackson

        #4
        Re: matplotlib, usetex

        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(rang e(10))
        pylab.show()


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





        Comment

        • Alexander Schmolck

          #5
          Re: matplotlib, usetex

          Bill Jackson <jackson@hotmai l.comwrites:
          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(rang e(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



          Comment

          Working...