# DateFormatter + Latex issue

Hello list,

If I use DateFormatter with latex and lines breaks like this

DateFormatter("\n \n %b") I get an latex error:

http://pastebin.com/m5b186ded

Although, if I do not use the line breaks,

DateFormatter("%b")
The problem disappears.

Below is a script that reproduces what I’m talking about:

#Example:
from pylab import *
from matplotlib import rcParams
rcParams[‘text.usetex’] = True
fig = figure()
t = arange(100,110,.1)
u = sin(t)
v = cos(t)
quiver([t],[[0]*len(t)],u,v)
major = DayLocator([10,04])
minor = DayLocator()
majorF = DateFormatter("\n \n %b") # problem
#majorF = DateFormatter("%b") # no problem
minorF = DateFormatter(’%d’)
ax.xaxis.set_major_locator(major)
ax.xaxis.set_minor_locator(minor)
ax.xaxis.set_major_formatter(majorF)
ax.xaxis.set_minor_formatter(minorF)
gca().xaxis_date()
title(r"$\alpha \beta \gamma \delta$")
show()

I’m using the latest svn version with qt4 as backend.

Thanks, Filipe

15/02/10 @ 19:22 (-0500), thus spake Filipe Pires Alvarenga Fernandes:

Hello list,

If I use DateFormatter with latex and lines breaks like this
>>> DateFormatter("\n \n %b") I get an latex error:

http://pastebin.com/m5b186ded

Although, if I do not use the line breaks,
>>> DateFormatter("%b")
The problem disappears.

Below is a script that reproduces what I'm talking about:

#Example:
from pylab import *
from matplotlib import rcParams
rcParams['text.usetex'] = True
fig = figure()
t = arange(100,110,.1)
u = sin(t)
v = cos(t)
quiver([t],[[0]*len(t)],u,v)
major = DayLocator([10,04])
minor = DayLocator()
majorF = DateFormatter("\n \n %b") # problem

^^ ^^
A common mistake.
You forgot to escape the "\" characters.

Bye.

Ernest

Thanks Ernest, I had no idea that the DateFormatter was going to be treated as latex as well.

However, escaping the \ with another \ did not worked.
I tried:

majorF = DateFormatter("\n \n %b")

How should I escape the \n ?

···

majorF = DateFormatter("\n \n %b") # problem

^^ ^^

A common mistake.

You forgot to escape the “” characters.

Bye.

Ernest

16/02/10 @ 09:03 (-0500), thus spake Filipe Pires Alvarenga Fernandes:

Thanks Ernest, I had no idea that the DateFormatter was going to be treated
as latex as well.

Yes, all strings are processed by LaTeX.

However, escaping the \ with another \ did not worked.
I tried:

majorF = DateFormatter("\\n \\n %b")

How should I escape the \n ?

In theory, "\\n \\n %b" or r"\n \n %b", however only the former
seems to work in my computer.

There's another problem: \n is not a valid LaTeX command.
I tried with \\ and with \newline but neither appear to work.
\vspace{10pts} does insert whitespace, however I am not sure if
it's the proper way of doing it...

Bye.

···

> majorF = DateFormatter("\n \n %b") # problem
> ^^ ^^
> A common mistake.
> You forgot to escape the "\" characters.
>
> Bye.
>
> Ernest
>

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

“\” works for titles and label, but not for DateFormatter, but \vspace did the trick!

Thanks again for the help.

ps: I’m new to python, but maybe there is a way to mix Latex and unicode?

···

as latex as well.

Yes, all strings are processed by LaTeX.

However, escaping the \ with another \ did not worked.

I tried:

majorF = DateFormatter("\n \n %b")

How should I escape the \n ?

In theory, “\n \n %b” or r"\n \n %b", however only the former

seems to work in my computer.

There’s another problem: \n is not a valid LaTeX command.

I tried with \ and with \newline but neither appear to work.

\vspace{10pts} does insert whitespace, however I am not sure if

it’s the proper way of doing it…

Bye.

majorF = DateFormatter("\n \n %b") # problem

                     ^^  ^^


A common mistake.

You forgot to escape the “” characters.

Bye.

Ernest

Thanks Ernest, I had no idea that the DateFormatter was going to be treated

16/02/10 @ 16:20 (-0500), thus spake Filipe Pires Alvarenga Fernandes:

"\\" works for titles and label, but not for DateFormatter, but \vspace did
the trick!

Thanks again for the help.

ps: I'm new to python, but maybe there is a way to mix Latex and unicode?

Yes, the inputenc package from latex lets you use unicode.
plt.rc('text.latex', preamble='\usepackage[utf]{inputenc}')

Note that this setting is not officially supported, whatever
that means

I also like the txfonts package:
\usepackage[varg]{txfonts}

which changes the default font to Times, including the text in
mathematical expressions. It looks great.

Cheers.

Ernest

Can you (or someone else) confirm this? I don't think "pts" is a
proper tex unit and it should be \vspace{10pt}. Maybe this is a typo
in the email. I'm asking this because it does not work for me, and I
don't think it is supposed to work (but I may be wrong).

Regards,

-JJ

···

On Tue, Feb 16, 2010 at 4:05 PM, Ernest Adrogué <eadrogue@...361...> wrote:

\vspace{10pts} does insert whitespace, however I am not sure if
it's the proper way of doing it...

Good tip. I also like \usapackage{fourier} to get the utopia fonts, which are particularly useful since I'm always plotting concentrations and having a upright mu ($\othermu$) is really nice.

-paul h.

···

-----Original Message-----
Sent: Tuesday, February 16, 2010 1:58 PM
To: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] DateFormatter + Latex issue

16/02/10 @ 16:20 (-0500), thus spake Filipe Pires Alvarenga Fernandes:
> "\\" works for titles and label, but not for DateFormatter, but
\vspace did
> the trick!
>
> Thanks again for the help.
>
> ps: I'm new to python, but maybe there is a way to mix Latex and
unicode?

Yes, the inputenc package from latex lets you use unicode.
plt.rc('text.latex', preamble='\usepackage[utf]{inputenc}')

Note that this setting is not officially supported, whatever
that means

I also like the txfonts package:
\usepackage[varg]{txfonts}

which changes the default font to Times, including the text in
mathematical expressions. It looks great.

If what you want is to have more padding for the major tick labels, I
recommend you to use

If you don't like to change the global setting, you may set the
ticklabel padding for an specific axis. Try

for tck in ax.xaxis.get_major_ticks():
tck.label1 = tck._get_text1()

Regards,

-JJ

···

On Tue, Feb 16, 2010 at 4:20 PM, Filipe Pires Alvarenga Fernandes <ocefpaf@...287...> wrote:

"\\" works for titles and label, but not for DateFormatter, but \vspace did
the trick!

Thanks again for the help.

ps: I'm new to python, but maybe there is a way to mix Latex and unicode?

> as latex as well.

Yes, all strings are processed by LaTeX.

>
> However, escaping the \ with another \ did not worked.
> I tried:
>
> majorF = DateFormatter("\\n \\n %b")
>
> How should I escape the \n ?

In theory, "\\n \\n %b" or r"\n \n %b", however only the former
seems to work in my computer.

There's another problem: \n is not a valid LaTeX command.
I tried with \\ and with \newline but neither appear to work.
\vspace{10pts} does insert whitespace, however I am not sure if
it's the proper way of doing it...

Bye.

>
> > majorF = DateFormatter("\n \n %b") # problem
> > ^^ ^^
> > A common mistake.
> > You forgot to escape the "\" characters.
> >
> > Bye.
> >
> > Ernest

Thanks Ernest, I had no idea that the DateFormatter was going to be
treated

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi,

16/02/10 @ 17:01 (-0500), thus spake Jae-Joon Lee:

> \vspace{10pts} does insert whitespace, however I am not sure if
> it's the proper way of doing it...
>

Can you (or someone else) confirm this? I don't think "pts" is a
proper tex unit and it should be \vspace{10pt}. Maybe this is a typo
in the email. I'm asking this because it does not work for me, and I
don't think it is supposed to work (but I may be wrong).

You're right!
prints a "s" before the space, which I didn't see before.
Now, \vspace{10pt} doesn't work for me... it simply does nothing.

Bye.

···

On Tue, Feb 16, 2010 at 4:05 PM, Ernest Adrogué <eadrogue@...361...> wrote:

Regards,

-JJ

JJ:
Wonderful, simple and much less messy and Latex+unicode. Although, now I’m fascinated by the Latex possibilities!

Ernest:
I haven’t notice the “s” before when using “pts”, but what is really strange is that “pt” does not work!

Thank you all again, Filipe

As I said, it is not supposed to work, because of some technical
reason. When there is a single line of text, it is hardly possible to
get to know the original baseline of the text.

By the way, the original problem that "\n\n %b" didn't work seems like
a actual bug (it is supposed to work without escaping '\n'). This
should now be fixed in the svn (r8135 in maint. branch and r8136 in
instead of fiddling with newlines and etc.

Regards,

-JJ

···

On Tue, Feb 16, 2010 at 5:25 PM, Filipe Pires Alvarenga Fernandes <ocefpaf@...287...> wrote:

I haven't notice the "s" before when using "pts", but what is really
strange is that "pt" does not work!

I think it means that Darren, who did most of the heavy lifting for
these features, was getting tired of the endless line of additional
things TeX users wanted to do and the difficulties supporting these
across all platforms (eg MikTex on Windows) and drew a line in the
sand saying "I'll add this stuff but if you report problems I may not
stay up all night trying to fix them".

···

On Tue, Feb 16, 2010 at 3:57 PM, Ernest Adrogué <eadrogue@...361...> wrote:

16/02/10 @ 16:20 (-0500), thus spake Filipe Pires Alvarenga Fernandes:

"\\" works for titles and label, but not for DateFormatter, but \vspace did
the trick!

Thanks again for the help.

ps: I'm new to python, but maybe there is a way to mix Latex and unicode?

Yes, the inputenc package from latex lets you use unicode.
plt.rc('text.latex', preamble='\usepackage[utf]{inputenc}')

Note that this setting is not officially supported, whatever
that means

That is a fair explanation. Adding arbitrary lines to the latex
preamble adds an incredible amount of flexibility if you are a user,
and it provides plenty of rope with which to hang yourself if you are
a developer (answering questions/problems related to people writing
code!). At the time, we had finally shaped the latex backend into
something that worked across platforms (and different versions of
latex installations), plus I was also finishing up grad school and
feature to the library. But people really wanted it so we compromised.

Darren

···

On Tue, Feb 16, 2010 at 9:53 PM, John Hunter <jdh2358@...287...> wrote:

On Tue, Feb 16, 2010 at 3:57 PM, Ernest Adrogué <eadrogue@...361...> wrote:

16/02/10 @ 16:20 (-0500), thus spake Filipe Pires Alvarenga Fernandes:

"\\" works for titles and label, but not for DateFormatter, but \vspace did
the trick!

Thanks again for the help.

ps: I'm new to python, but maybe there is a way to mix Latex and unicode?

Yes, the inputenc package from latex lets you use unicode.
plt.rc('text.latex', preamble='\usepackage[utf]{inputenc}')

Note that this setting is not officially supported, whatever
that means

I think it means that Darren, who did most of the heavy lifting for
these features, was getting tired of the endless line of additional
things TeX users wanted to do and the difficulties supporting these
across all platforms (eg MikTex on Windows) and drew a line in the
sand saying "I'll add this stuff but if you report problems I may not
stay up all night trying to fix them".

Wow. This is really useful and perhaps, should be placed in a wiki
somewhere. Is this a common enough task to warrant a method?

Being unfamiliar with the Tick class, I wouldn't have expected that it
would have been necessary to reassign label1 (after setting the pad
size).

···

On Tue, Feb 16, 2010 at 2:03 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

If what you want is to have more padding for the major tick labels, I
recommend you to use

If you don't like to change the global setting, you may set the
ticklabel padding for an specific axis. Try

for tck in ax.xaxis.get_major_ticks():
tck.label1 = tck._get_text1()

Regards,

-JJ

Compromised or not, it's a great feature and I'm *really* happy it made it was included! Thanks for all of the effort.

-Paul H.

···

On Tue, Feb 16, 2010 at 9:53 PM, John Hunter <jdh2358@...287...> wrote:
> I think it means that Darren, who did most of the heavy lifting for
> these features, was getting tired of the endless line of additional
> things TeX users wanted to do and the difficulties supporting these
> across all platforms (eg MikTex on Windows) and drew a line in the
> sand saying "I'll add this stuff but if you report problems I may not
> stay up all night trying to fix them".

From: Darren Dale [mailto:dsdale24@…287…]
Sent: Wednesday, February 17, 2010 4:55 AM
That is a fair explanation. Adding arbitrary lines to the latex
preamble adds an incredible amount of flexibility if you are a user,
and it provides plenty of rope with which to hang yourself if you are
a developer (answering questions/problems related to people writing