I try to color underlay the axis labels in matplotlib
and create a pdf
from it. Something like this
I tried the following
import matplotlib
matplotlib.use('ps')
import matplotlib.pyplot as plt
plt.rc('text', usetex=True)
plt.rcParams['text.latex.preamble'] = [r'\usepackage{xcolor}']
_, ax = plt.subplots()
plt.plot([0, 1], [0, 1], 'r')
plt.plot([0, 1], [0, 2], 'b')
ax.set_ylabel( \
r'{\colorlet{temp}{.}\color{red}\underline{\color{temp}{A}}\color{temp}},' +
r'{\colorlet{temp}{.}\color{blue}\underline{\color{temp}{B}}\color{temp}}' +
' (m)')
plt.savefig('test.pdf')
plt.savefig('test.ps')
plt.show()
which works fine for the ps
but not the pdf
(The labels are still black). Unfortunatelly ps2pdf
screws up other parts of my plot so I cannot use it.
Related:
Partial coloring of text in matplotlib
Latex code from: https://tex.stackexchange.com/questions/57070/how-to-color-over-underline-or-other-ways-to-highlight-substituted-expressions