4

I try to color underlay the axis labels in matplotlib and create a pdf from it. Something like this

example

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

Community
  • 1
  • 1
magu_
  • 4,766
  • 3
  • 45
  • 79
  • Have you tried pdfPages? http://matplotlib.org/api/backend_pdf_api.html – YOBA Sep 18 '15 at 10:40
  • @YOBA. Thank you for your suggestion. I tried it out now. But unfortunately its still black and white – magu_ Sep 18 '15 at 15:45

0 Answers0