X Tutup
Skip to content

Inconsistent behavior of backends when rendering latex colors #6724

@madphysicist

Description

@madphysicist

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesDifficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesGood first issueOpen a pull request against these issues if there are no active ones!keepItems to be ignored by the “Stale” Github Actiontopic: text/usetex

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup