-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
MPL 1.5.1 on Python 3.5 (Anaconda) running on Red Hat 6.5.
This issue is a followup to the discussion on matplotlib-users Creating Colored Axis Labels using LaTeX in Interactive Mode, which in turn is a followup to Stack Overflow Inconsistent rendering of hdashrule in matplotlib axis labels.
In my attempts to get latex colors to show up correctly in axis labels using interactive backends with LaTeX enabled, I came across http://matplotlib.org/users/pgf.html. I expected to be able to do the following:
import matplotlib as mpl
from matplotlib.backends.backend_pgf import FigureCanvasPgf
matplotlib.backend_bases.register_backend('png', FigureCanvasPgf)
from matplotlib import pyplot as plt
matplotlib.rc('pgf', texsystem='pdflatex') # from running latex -v
preamble = matplotlib.rcParams.setdefault('pgf.preamble', [])
preamble.append(r'\usepackage{color}')
preamble.append(r'\usepackage{dashrule}')
ax = plt.plot((0, 1), (1, 2))[0].axes
ax.set_ylabel(r'Y $\;$ \textcolor[rgb]{1.0, 0.0, 0.0}{\hdashrule[0.5ex]{3cm}{1pt}{1pt 0pt}}')
ax.set_xlabel(r'N $\;$ \textcolor[rgb]{0.0, 1.0, 0.0}{\rule[0.5ex]{3cm}{1pt}}')
plt.savefig('test.png')
With the default backend, this does not work at all, and the labels are rendered as raw strings containing TeX commands. With mpl.use('pgf'), the lines in the labels are rendered black instead of the intended color. Please see the SO question and mailing list discussion for more info.