empty mathtext "$$" in labels generates an exception

Hi,

using an empty mathtext "$$" in labels generates an exception. See example and traceback below.

/J�rgen

from pylab import *
from numpy import *

x=arange(0,2*pi,0.1)
plot(x,sin(x))
title(r"$$")
show()

Exception in Tkinter callback
Traceback (most recent call last):
   File "C:\python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
     return self.func(*args)
   File "c:\python\external\matplotlib-trunk\build\lib.win32-2.5\matplotlib\backends\backend_tkagg.py", line 188, in resize
     self.show()
   File "c:\python\external\matplotlib-trunk\build\lib.win32-2.5\matplotlib\backends\backend_tkagg.py", line 191, in draw
     FigureCanvasAgg.draw(self)
   File "c:\python\external\matplotlib-trunk\build\lib.win32-2.5\matplotlib\backends\backend_agg.py", line 255, in draw
     self.figure.draw(self.renderer)
   File "c:\python\external\matplotlib-trunk\build\lib.win32-2.5\matplotlib\figure.py", line 796, in draw
     for a in self.axes: a.draw(renderer)
   File "c:\python\external\matplotlib-trunk\build\lib.win32-2.5\matplotlib\axes.py", line 1494, in draw
     a.draw(renderer)
   File "c:\python\external\matplotlib-trunk\build\lib.win32-2.5\matplotlib\text.py", line 295, in draw
     bbox, info = self._get_layout(renderer)
   File "c:\python\external\matplotlib-trunk\build\lib.win32-2.5\matplotlib\text.py", line 195, in _get_layout
     line, self._fontproperties, ismath=self.is_math_text(line))
   File "c:\python\external\matplotlib-trunk\build\lib.win32-2.5\matplotlib\backends\backend_agg.py", line 134, in get_text_width_height_descent
     self.mathtext_parser.parse(s, self.dpi, prop)
   File "c:\python\external\matplotlib-trunk\build\lib.win32-2.5\matplotlib\mathtext.py", line 2706, in parse
     box = self._parser.parse(s, font_output, fontsize, dpi)
   File "c:\python\external\matplotlib-trunk\build\lib.win32-2.5\matplotlib\mathtext.py", line 2186, in parse
     str(err)]))
ValueError:
$$
^
Expected end of text (at char 0), (line:1, col:1)

My guess is that this is a LaTeX error. If you enter $$ in a normal LaTeX document, you will get:

pdflatex -interaction=nonstopmode -file-line-error-style exited with status 1

This error comes from the fact that double dollar signs ($$) are used to wrap display equations (single dollar signs are used to wrap inline equations). If you were to instead write “$ $” (or “$$ $$”), you shouldn’t get an error.

-Tony

···

On Jun 3, 2008, at 4:18 PM, Jörgen Stenarson wrote:

using an empty mathtext “$$” in labels generates an exception. See
example and traceback below.

Tony Yu skrev:

using an empty mathtext "$$" in labels generates an exception. See
example and traceback below.

My guess is that this is a LaTeX error. If you enter $$ in a normal LaTeX document, you will get:

I don't think so. I'm using mathtext i.e. matplotlibs own latex interpreter. And I get the same error with $$ $$.

/J�rgen

···

On Jun 3, 2008, at 4:18 PM, J�rgen Stenarson wrote:

I see that this isn't a LaTeX error, but I think Tony's comment is still somewhat valid. Since mathtext's parser is a direct subset of LaTeX's, and since $$ is a syntax error in LaTeX, it also is in mathtext. (This is really a side effect of make such a direct copy of the parser, rather than a deliberate choice). We can probably add a workaround to the parser, but I personally don't have a problem with it raising an exception. It doesn't seem to be a very useful thing to be able to do. What's your use case?

Cheers,
Mike

J�rgen Stenarson wrote:

···

Tony Yu skrev:
  

On Jun 3, 2008, at 4:18 PM, J�rgen Stenarson wrote:
    

using an empty mathtext "$$" in labels generates an exception. See
example and traceback below.
      

My guess is that this is a LaTeX error. If you enter $$ in a normal LaTeX document, you will get:

I don't think so. I'm using mathtext i.e. matplotlibs own latex interpreter. And I get the same error with $$ $$.

/J�rgen

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Hi,

Some more thoughts about hist():

A "range" parameter should be added and used in histogram()

A new histogram should get a new colour, just like plot() does

The "step" type should default to fill=False

Actually, personally I hardly ever use bar histograms at all, so if step-mode (unfilled) was made default I wouldn't complain...

And not directly related to hist():

I think the pan/zoom tool should be on by default when a new figure opens. As it is now, we always need to press some button no matter what we want to do. pan/zoom is a good guess (at least for me)!

Thanks all developers for creating what has become my default plotting tool! I will never leave the python shell again.

(from kitchen import coffee)

Cheers,
Olle

Olle Engdeg�rd wrote:

Hi,

Some more thoughts about hist():

A "range" parameter should be added and used in histogram()

Hi Olle,
   what do you mean by "range" parameter. What should this parameter actually do ?

   I just committed a patch to the trunk that adds the features as you and also Erik Tollerud proposed (expect for the range thing).

Manuel

···

A new histogram should get a new colour, just like plot() does

The "step" type should default to fill=False

Actually, personally I hardly ever use bar histograms at all, so if step-mode (unfilled) was made default I wouldn't complain...

And not directly related to hist():

I think the pan/zoom tool should be on by default when a new figure opens. As it is now, we always need to press some button no matter what we want to do. pan/zoom is a good guess (at least for me)!

Thanks all developers for creating what has become my default plotting tool! I will never leave the python shell again.

(from kitchen import coffee)

Cheers,
Olle

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

what do you mean by "range" parameter. What should this parameter actually do ?

Actually just pass it along to numpy.histogram(). I guess it just ignores all data outside the range.

Cheers,
Olle

Maybe the best solution here is to simply add a "histogramkwargs"
argument that gets passed into nump.histogram - that way, the user can
also do things like have a weighted histogram if they so desire
(probably want to make sure no one passes in {'new':False}, though, as
that would screw everything up).

···

On Fri, Jun 6, 2008 at 6:39 PM, Olle Engdegård <olle@...599...> wrote:

what do you mean by "range" parameter. What should this parameter actually
do ?

Actually just pass it along to numpy.histogram(). I guess it just ignores
all data outside the range.

Cheers,
Olle

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

--
Erik Tollerud
Graduate Student
Center For Cosmology
Department of Physics and Astronomy
2142 Frederick Reines Hall
University of California, Irvine
Office Phone: (949)824-2587
Cell: (651)307-9409
etolleru@...244...