laolux
laolux

Reputation: 1565

matplotlib axis tick labels moving up and down when exporting to pgf

I am plotting some function and use radians for the ticks of the x-axis. Looks great it matplotlib and when exported to png or svg, but when exporting to pgf, then π (and to a lower extent -π) is a lot closer to the x-axis than the other labels. This looks awful. I made screenshots of both versions to show what I mean. Is there a way to fix the position of π in the pgf output? I would like to stick with pgf, because I use the graph with LaTeX and it looks nices if all fonts match exactly.

png version, looking good

png version, looking good

pgf version, looking bad. See how π seems to be out of line.

pgf version, looking bad

The python code for creating the graphs:

import matplotlib.pyplot as plt
import numpy as np
import basic_units

x = np.linspace(-2*np.pi, 2*np.pi, 100)
y = np.sin(x)

fig = plt.figure()
ax = fig.add_subplot(111)
domain = np.array([-2*np.pi*basic_units.radians, 2*np.pi*basic_units.radians])
ax.set_xlim(domain)
ax.plot(x, y)
fig.savefig("nice.png")
fig.savefig("nice.svg")
fig.savefig("ugly.pgf")
plt.show()

And the latex document to embed the pgf file

\documentclass{standalone}
\usepackage{graphicx}
\usepackage{pgf}

\begin{document}
\includegraphics{nice}
\input{ugly.pgf}
\end{document}

Upvotes: 1

Views: 188

Answers (0)

Related Questions