fonts for log axis?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

fonts for log axis?

Bugzilla from arnd.baecker@web.de
Hi,

for this example

  from pylab import *
  x=arange(10)
  semilogy(x,1+x)

the y-axis has a different font (italic) than the x-axis (sans-serif).
Looking at the code, this is because it is set as math text ($ ...$).
Is there a trick to ensure a sans-serif font for the y-axis?
(I would like to use matplotlib plots in a presentation
and sans-serif fonts are better suited for this.)

Best,

Arnd



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: fonts for log axis?

John Hunter-8
>>>>> "arnd" == arnd baecker <[hidden email]> writes:
    arnd> the y-axis has a different font (italic) than the x-axis
    arnd> (sans-serif).  Looking at the code, this is because it is
    arnd> set as math text ($ ...$).  Is there a trick to ensure a
    arnd> sans-serif font for the y-axis?  (I would like to use
    arnd> matplotlib plots in a presentation and sans-serif fonts are
    arnd> better suited for this.)

What version of mpl are you using?  I thought in a previous post you
said you were using cvs (could be mistaken).  I wrote an extension to
text.py to special case exponential formatting specifically to solve
the mismatched fonts problem.  So make sure you are using a current
problem of matplotlib and if you still have the problem check your
input against the regex in matplotlib.text.Text

    # special case superscripting to speedup logplots
    _rgxsuper = re.compile('\$([\-+0-9]+)\^\{(-?[0-9]+)\}\$')

If you can fix up this expression to include your case that would be
most helpful.

Thanks,
JDH


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: fonts for log axis?

Bugzilla from arnd.baecker@web.de
Hi John,

On Sat, 3 Sep 2005, John Hunter wrote:

> >>>>> "arnd" == arnd baecker <[hidden email]> writes:
>     arnd> the y-axis has a different font (italic) than the x-axis
>     arnd> (sans-serif).  Looking at the code, this is because it is
>     arnd> set as math text ($ ...$).  Is there a trick to ensure a
>     arnd> sans-serif font for the y-axis?  (I would like to use
>     arnd> matplotlib plots in a presentation and sans-serif fonts are
>     arnd> better suited for this.)
>
> What version of mpl are you using?  I thought in a previous post you
> said you were using cvs (could be mistaken).

You remember the version I am running better than I do ;-).
In [1]: import matplotlib
In [2]: matplotlib.__version__
Out[2]: '0.84.cvs.2'

> I wrote an extension to
> text.py to special case exponential formatting specifically to solve
> the mismatched fonts problem.  So make sure you are using a current
> problem of matplotlib and if you still have the problem check your
> input against the regex in matplotlib.text.Text
>
>     # special case superscripting to speedup logplots
>     _rgxsuper = re.compile('\$([\-+0-9]+)\^\{(-?[0-9]+)\}\$')
>
> If you can fix up this expression to include your case that would be
> most helpful.

I think the expression is alright:
I looked at matplotlib/text.py - class Text. It seems that
for this example the routine does not pass by the
first use of self._rgxsuper:


        print "Arriving here1"
        if angle==0:
            print "Arriving here2"
            if ismath!='TeX':            # <==== change to "==" here?
                print "Arriving here3"
  m = None
            else:
                m = self._rgxsuper.match(self._text)
                print "passing by here..."
            print "Arriving here4"
            if m is not None and not rcParams['text.usetex']:
                print "Arriving here5"
                bbox, info = self._get_layout_super(self._renderer, m)
                base, xt, yt = info[0]
                renderer.draw_text(gc, xt, yt, base,
                                   self._fontproperties, angle,
                                   ismath=False)

                exponent, xt, yt, fp = info[1]
                renderer.draw_text(gc, xt, yt, exponent,
                                   fp, angle,
                                   ismath=False)
                return

However, changing ismath!='TeX' to ismath=='TeX'
seems to work (for this particular example): I.e. I get
the non-math fonts on the vertical axis.
Can you confirm that this change is the correct solution?

Best,

Arnd

P.S.: BTW: splattering the prints around seems like poor-mans
debugging ;-) Are there better solutions available?



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: fonts for log axis?

John Hunter-8
>>>>> "Arnd" == Arnd Baecker <[hidden email]> writes:
    Arnd> I think the expression is alright: I looked at
    Arnd> matplotlib/text.py - class Text. It seems that for this
    Arnd> example the routine does not pass by the first use of
    Arnd> self._rgxsuper:


It looks like you're right -- good catch.  It should read

            if ismath=='TeX': m = None
            else: m = self._rgxsuper.match(self._text)
            if m is not None:
                bbox, info = self._get_layout_super(self._renderer, m)

    Arnd> P.S.: BTW: splattering the prints around seems like
    Arnd> poor-mans debugging ;-) Are there better solutions
    Arnd> available?

It is certainly poor-man's debugging, but it is a time honored
tradition that has served me well.  Of course, you could use the
python debugger, and it sometimes helps to embed an ipython shell in
the code

  from IPython.Shell import IPShellEmbed
  ipshell = IPShellEmbed()
  ipshell() # this call anywhere in your program will start IPython


If you place this inside a function, a shell will pop up with the
local namespace which you can then inspect.

JDH


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re[2]: fonts for log axis?

Alan G Isaac
Arnd> P.S.: BTW: splattering the prints around seems like
Arnd> poor-mans debugging ;-) Are there better solutions
Arnd> available?

The logging module allows you to use essentially the same
strategy with a finer level of control.

fwiw,
Alan Isaac




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users