Text annotation misaligned with png backend.

View: New views
2 Messages — Rating Filter:   Alert me  

Text annotation misaligned with png backend.

by Johan Grönqvist :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello List,

I am so far happy with the output form matplotlib, but I recently
started annotating my plots, and when saving to png-format, the
annotations do not look very nice. When saving to eps format, I do not
see the same problems.

Saving to eps and converting to png seems to be a good workaround for me.

The problem is that the letters in the same word (on the same line) are
not aligned, some are drawn to far up or down.

png and eps figures are attached. Example script and version number
(0.99.0) below.

Am I misusing matplotlib? Is this a bug?


Regards

johan








Minimal example:
-----------------------
import matplotlib.pyplot as plt
import numpy as np

plt.figure()

x = [0]
plt.plot(x, x)

plt.annotate("units are important, $7.64358$,
$\\frac{\mathrm{k}\mathrm{m}}{\mathrm{s^2}}$",
              xy = (0,0),
              xycoords = "data",
              xytext = (0.2, 0.6),
              textcoords = "figure fraction",
              arrowprops = dict(arrowstyle = "->",
                                connectionstyle = "arc"))


plt.savefig("pyplot_text.png")
plt.savefig("pyplot_text.eps")
plt.show()
-----------------------


Expected result: An empty plot with a nice annotation on screen, in a
png-file, and in an eps-file

Result: Empty plots with annotation displaying differently in the three
cases. In the png file, the letters u and r  and the digit 7 appear
slightly above the correct position, and the m in the unit km appears
slightly below the correct position. In the screen output, the m is
correct, but the u and r show the same problem as in the png file. In
the eps file, all seems to be well.

My os is debian (testing), and I obtain matplotlib and all related
software from the debian repositories.

johan@johan-laptop:~$ uname -a
Linux johan-laptop 2.6.30-2-amd64 #1 SMP Fri Sep 25 22:16:56 UTC 2009
x86_64 GNU/Linux
johan@johan-laptop:~$ python -c "import matplotlib; print
matplotlib.__version__"
0.99.0







------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

pyplot_text.eps (39K) Download Attachment
pyplot_text.png (26K) Download Attachment

Re: Text annotation misaligned with png backend.

by Jae-Joon Lee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't see such problem in my installations.
I may be wrong but It seems to me that it is a font issue (I believe
you're not using usetex mode).

Can you try to use other fonts?

For example, my current installation picks up the following font (Vera Serif?).

In [10]: matplotlib.font_manager.findfont(None)
Out[10]: '/astro/research/jul27/local/lib/python2.5/site-packages/matplotlib/mpl-data/fonts/ttf/VeraSe.ttf'

Regards,

-JJ



2009/10/30 Johan Grönqvist <johan.gronqvist@...>:

> Hello List,
>
> I am so far happy with the output form matplotlib, but I recently started
> annotating my plots, and when saving to png-format, the annotations do not
> look very nice. When saving to eps format, I do not see the same problems.
>
> Saving to eps and converting to png seems to be a good workaround for me.
>
> The problem is that the letters in the same word (on the same line) are not
> aligned, some are drawn to far up or down.
>
> png and eps figures are attached. Example script and version number (0.99.0)
> below.
>
> Am I misusing matplotlib? Is this a bug?
>
>
> Regards
>
> johan
>
>
>
>
>
>
>
>
> Minimal example:
> -----------------------
> import matplotlib.pyplot as plt
> import numpy as np
>
> plt.figure()
>
> x = [0]
> plt.plot(x, x)
>
> plt.annotate("units are important, $7.64358$,
> $\\frac{\mathrm{k}\mathrm{m}}{\mathrm{s^2}}$",
>             xy = (0,0),
>             xycoords = "data",
>             xytext = (0.2, 0.6),
>             textcoords = "figure fraction",
>             arrowprops = dict(arrowstyle = "->",
>                               connectionstyle = "arc"))
>
>
> plt.savefig("pyplot_text.png")
> plt.savefig("pyplot_text.eps")
> plt.show()
> -----------------------
>
>
> Expected result: An empty plot with a nice annotation on screen, in a
> png-file, and in an eps-file
>
> Result: Empty plots with annotation displaying differently in the three
> cases. In the png file, the letters u and r  and the digit 7 appear slightly
> above the correct position, and the m in the unit km appears slightly below
> the correct position. In the screen output, the m is correct, but the u and
> r show the same problem as in the png file. In the eps file, all seems to be
> well.
>
> My os is debian (testing), and I obtain matplotlib and all related software
> from the debian repositories.
>
> johan@johan-laptop:~$ uname -a
> Linux johan-laptop 2.6.30-2-amd64 #1 SMP Fri Sep 25 22:16:56 UTC 2009 x86_64
> GNU/Linux
> johan@johan-laptop:~$ python -c "import matplotlib; print
> matplotlib.__version__"
> 0.99.0
>
>
>
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users