TeX labels

Regarding my previous message on TeX labels, it would

    > seem that having parentheses in there mix up the
    > alignment. Not "regular" text, as i previously
    > suggested.

This makes more sense.

All the symbols that come from cmex10 (a TeX computer modern font)
have some funny alignment that I have not been able to figure out
properly and so I deal with them in some hackish ways that you have
just experienced. Thanks for the report, because it lets me know
where the hacks are failing.

But your post gave me a better idea. Since parentheses are so common,
and are defined in a number of the font files, I can use the
parentheses from a font file that doesn't have this strange offset
problem.

Edit matplotlib.mathtext.py and comment out the following code and
replace it with the code below it

    #'(' : ('cmex10.ttf', 'A1'),
    #r'\leftparen' : ('cmex10.ttf', 'A1'),
    #')' : ('cmex10.ttf', 'A2'),
    #r'\rightparen' : ('cmex10.ttf', 'A2'),

    #'[' : ('cmex10.ttf', 'A3'),
    #r'\leftbracket' : ('cmex10.ttf', 'A3'),
    #']' : ('cmex10.ttf', 'A4'),
    #r'\rightbracket' : ('cmex10.ttf', 'A4'),

    '(' : ('cmr10.ttf', '28'),
    r'\leftparen' : ('cmr10.ttf', '28'),
    ')' : ('cmr10.ttf', '29'),
    r'\rightparen' : ('cmr10.ttf', '29'),

    '[' : ('cmr10.ttf', '5B'),
    r'\leftbracket' : ('cmr10.ttf', '5B'),
    ']' : ('cmr10.ttf', '5D'),
    r'\rightbracket' : ('cmr10.ttf', '5D'),

This takes the symbols (, ), [ and ] from computer modern roman rather
than computer modern extensions and the alignment works perfectly.

Note also that vertical alignment of mathtext (ylabels) is not yet
supported. Feel free to bug me if this is an issue.

I expect plenty more issues to crop up with mathtext since it is
not widely tested and I am not Knuth so please let me know when you
find them. The author of pyparsing has been helping me with the
parsing problem that prevents x_i_j from parsing properly but I
haven't been able to get to it yet.

    > A final comment, using gca().set_yticks( ... ) prints a
    > large number of messages "<matplotlib.axis.YTick
    > instance at ...>". There must be a print somethere.

You're in interactive mode right? In a python shell

2+2

4

x = 2+2

Ie, an expression which is not assigned to a name is printed in the
shell in interactive mode. set_ticks returns a list of tick labels to
allow you to do things like

  labels = gca().set_yticks(['a', 'b', 'c'])
  set(labels, 'color', 'r')

The point is, if you assign the return value of set_ticks a name, it
should no longer print to the shell. Ditto for other plot functions
that return a value. If this doesn't cure you, let me know. A
residual print is always a possibility.

JDH

John Hunter wrote:

"Dominique" == Dominique Orban <Dominique.Orban@...92...> writes:

    > Regarding my previous message on TeX labels, it would
    > seem that having parentheses in there mix up the
    > alignment. Not "regular" text, as i previously
    > suggested.

Your trick did it just fine. TeX titles and y-labels appear correctly now. Vertical y-labels are not an issue for me right now. Perhaps other users?

    > A final comment, using gca().set_yticks( ... ) prints a
    > large number of messages "<matplotlib.axis.YTick
    > instance at ...>". There must be a print somethere.

You're in interactive mode right? In a python shell

2+2

4

x = 2+2

Ie, an expression which is not assigned to a name is printed in the
shell in interactive mode. set_ticks returns a list of tick labels to
allow you to do things like

  labels = gca().set_yticks(['a', 'b', 'c'])
  set(labels, 'color', 'r')

The point is, if you assign the return value of set_ticks a name, it
should no longer print to the shell. Ditto for other plot functions
that return a value. If this doesn't cure you, let me know. A
residual print is always a possibility.

Well i agree with the above, but i wasn't in interactive mode. Moreover, gca().set_xticks doesn't print anything. Here is an example:

>>> import matplotlib
>>> matplotlib.use( 'TkAgg' )
>>> from matplotlib.matlab import *
>>> x = [1,2,3,4]
>>> y = [2,1,4,3]
>>> plot(x,y)
[<matplotlib.lines.Line2D instance at 0x01092B20>]
>>> show()
>>> gca().set_xticks( [1,2,3,4] )
>>> show()
>>> gca().set_yticks( [1,2,3,4] )
[<matplotlib.axis.YTick instance at 0x010738A0>, <matplotlib.axis.YTick instance at 0x010793F0>, <matplotlib.axis.YTick instance at 0x01079F08>, <matplotlib.axis.YTick instance at 0x01076A58>]
>>> show()

The two set_[xy]ticks commands work fine. For some reason though, set_yticks outputs tick instances in the terminal.

Cheers,
Dominique