Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

## [Matplotlib-users] fonts for log axis?

 [Matplotlib-users] fonts for log axis? From: - 2005-09-03 16:08:39 ```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 ```

 [Matplotlib-users] fonts for log axis? From: - 2005-09-03 16:08:39 ```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 ```
 Re: [Matplotlib-users] fonts for log axis? From: John Hunter - 2005-09-04 03:43:21 ```>>>>> "arnd" == arnd baecker 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 ```
 Re: [Matplotlib-users] fonts for log axis? From: Arnd Baecker - 2005-09-04 15:41:57 ```Hi John, On Sat, 3 Sep 2005, John Hunter wrote: > >>>>> "arnd" == arnd baecker 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? ```
 Re: [Matplotlib-users] fonts for log axis? From: John Hunter - 2005-09-04 17:44:40 ```>>>>> "Arnd" == Arnd Baecker 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 ```
 Re[2]: [Matplotlib-users] fonts for log axis? From: Alan G Isaac - 2005-09-04 18:02:48 ```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 ```