<div dir="ltr">I can confirm that this does not work as expected but I don't know exactly why.<div><br></div><div>With regards to your pgf example. It seems to be missing a \usepackage{<span style="line-height:1.5">dashrule}</span></div><div><br></div><div>The following runs for me but still generates the black non colored bars. </div><div>The # Text config seems to do nothing in my test so I'm not sure why you need to set it.</div><div><br></div><div>If I save the pgf backend to a .pgf file and include it in a texfile as below everything looks correct in that example</div><div><br></div><div>test.py</div><div>```</div><div><div>import matplotlib</div><div>from matplotlib.backends.backend_pgf import FigureCanvasPgf</div><div>matplotlib.backend_bases.register_backend('png', FigureCanvasPgf)</div><div>from matplotlib import pyplot as plt</div><div><br></div><div>matplotlib.rc('pgf', texsystem='pdflatex') # from running latex -v</div><div>preamble = matplotlib.rcParams.setdefault('pgf.preamble', [])</div><div>preamble.append(r'\usepackage{color}')</div><div>preamble.append(r'\usepackage{dashrule}')</div><div><br></div><div># Text config</div><div>#matplotlib.rc('text', usetex=True)</div><div># preamble = matplotlib.rcParams.setdefault('text.latex.preamble', [])</div><div>#preamble.append(r'\usepackage{color}')</div><div>#preamble.append(r'\usepackage{dashrule}')</div><div><br></div><div>ax = plt.plot((0, 1), (1, 2))[0].axes</div><div>ax.set_ylabel(r'Y $\;$ \textcolor[rgb]{1.0, 0.0, 0.0}{\hdashrule[0.5ex]{3cm}{1pt}{1pt 0pt}}')</div><div>ax.set_xlabel(r'N $\;$ \textcolor[rgb]{0.0, 1.0, 0.0}{\rule[0.5ex]{3cm}{1pt}}')</div><div>plt.savefig('test.pgf')</div><div>plt.savefig('test.png')</div></div><div>```</div><div><br></div><div>test.tex</div><div>```</div><div><div>\documentclass{article}</div><div><br></div><div>\usepackage[utf8]{inputenc}</div><div>\usepackage[english]{babel}</div><div><br></div><div>\usepackage{color}</div><div>\usepackage{dashrule}</div><div>\usepackage{pgf}</div><div><br></div><div>\begin{document}</div><div><br></div><div>\input{test.pgf}</div><div>\end{document}</div></div><div>```</div><div><br></div><div>and running pdflatex test.tex generates a test.pdf that looks as expected.</div><div><br></div><div>best</div><div>Jens</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, 11 Jul 2016 at 17:08 Joseph Fox-Rabinovitz <<a href="mailto:jfoxrabinovitz@gmail.com">jfoxrabinovitz@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Have an update on my previous question. I have tried to follow the<br>
instructions at <a href="http://matplotlib.org/users/pgf.html" rel="noreferrer" target="_blank">http://matplotlib.org/users/pgf.html</a> for settting up<br>
the PGF backend for PNG and PDF rendering. This method does not work<br>
either:<br>
<br>
import matplotlib as mpl<br>
from matplotlib.backends.backend_pgf import FigureCanvasPgf<br>
matplotlib.backend_bases.register_backend('png', FigureCanvasPgf)<br>
from matplotlib import pyplot as plt<br>
<br>
matplotlib.rc('pgf', texsystem='pdflatex') # from running latex -v<br>
preamble = matplotlib.rcParams.setdefault('pgf.preamble', [])<br>
preamble.append(r'\usepackage{color}')<br>
<br>
# Text config<br>
matplotlib.rc('text', usetex=True)<br>
preamble = matplotlib.rcParams.setdefault('text.latex.preamble', [])<br>
preamble.append(r'\usepackage{color}')<br>
<br>
ax = plt.plot((0, 1), (1, 2))[0].axes<br>
ax.set_ylabel(r'Y $\;$ \textcolor[rgb]{1.0, 0.0,<br>
0.0}{\hdashrule[0.5ex]{3cm}{1pt}{1pt 0pt}}')<br>
ax.set_xlabel(r'N $\;$ \textcolor[rgb]{0.0, 1.0,<br>
0.0}{\rule[0.5ex]{3cm}{1pt}}')<br>
plt.savefig('test.png')<br>
<br>
Yields the exact same figure and PNG file with the incorrect black<br>
lines as above. Note that turning off the three lines under `# Text<br>
config` makes the TeX commands print out verbatim, even in the saved<br>
figure. Perhaps there is a way to render the PNG correctly without<br>
pre-clobbering with the text system?<br>
<br>
Regards,<br>
<br>
-Joe<br>
<br>
<br>
<br>
On Mon, Jul 11, 2016 at 11:12 AM, Joseph Fox-Rabinovitz<br>
<<a href="mailto:jfoxrabinovitz@gmail.com" target="_blank">jfoxrabinovitz@gmail.com</a>> wrote:<br>
> I originally posted to Stack Overflow at<br>
> <a href="http://stackoverflow.com/q/38274681/2988730" rel="noreferrer" target="_blank">http://stackoverflow.com/q/38274681/2988730</a> (and accidentally to the<br>
> SourceForge version of this list).<br>
><br>
> I am trying to follow the answer at<br>
> <a href="http://stackoverflow.com/a/38008501/2988730" rel="noreferrer" target="_blank">http://stackoverflow.com/a/38008501/2988730</a> to an earlier question of<br>
> mine to create colored and styled legend-like entries. I have the<br>
> following code:<br>
><br>
> import matplotlib as mpl<br>
> mpl.use('ps')<br>
> from matplotlib import pyplot as plt<br>
><br>
> mpl.rc('text', usetex=True)<br>
> mpl.rc('text.latex', preamble='\\usepackage{color}\n\\usepackage{dashrule}')<br>
><br>
> plt.ion()<br>
> ax = plt.plot((0, 1), (1, 2))[0].axes<br>
> ax.set_ylabel(r'Y $\;$ \textcolor[rgb]{1.0, 0.0,<br>
> 0.0}{\hdashrule[0.5ex]{3cm}{1pt}{1pt 0pt}}')<br>
> ax.set_xlabel(r'N $\;$ \textcolor[rgb]{0.0, 1.0,<br>
> 0.0}{\rule[0.5ex]{3cm}{1pt}}')<br>
> plt.savefig('<a href="http://test.ps" rel="noreferrer" target="_blank">test.ps</a>')<br>
><br>
> The result is as expected. The labels contain black text with a red<br>
> line on the Y label and a green line on the X label:<br>
> <a href="http://i.stack.imgur.com/JCiLI.png" rel="noreferrer" target="_blank">http://i.stack.imgur.com/JCiLI.png</a>.<br>
><br>
> However, when I try the exact same set of commands without the<br>
> `mpl.use('ps')` line (using `'qt4agg'` backend on my system), the<br>
> figure neither saves corectly nor shows up correctly on screen:<br>
><br>
> import matplotlib as mpl<br>
> from matplotlib import pyplot as plt<br>
><br>
> mpl.rc('text', usetex=True)<br>
> mpl.rc('text.latex', preamble='\\usepackage{color}\n\\usepackage{dashrule}')<br>
><br>
> plt.ion()<br>
> ax = plt.plot((0, 1), (1, 2))[0].axes<br>
> ax.set_ylabel(r'Y $\;$ \textcolor[rgb]{1.0, 0.0,<br>
> 0.0}{\hdashrule[0.5ex]{3cm}{1pt}{1pt 0pt}}')<br>
> ax.set_xlabel(r'N $\;$ \textcolor[rgb]{0.0, 1.0,<br>
> 0.0}{\rule[0.5ex]{3cm}{1pt}}')<br>
><br>
> plt.savefig('test.png')<br>
> plt.show()<br>
><br>
> The result of `plt.savefig` (<a href="http://i.stack.imgur.com/h2LXn.png" rel="noreferrer" target="_blank">http://i.stack.imgur.com/h2LXn.png</a>) and<br>
> `plt.show` (<a href="http://i.stack.imgur.com/0Ow7c.png" rel="noreferrer" target="_blank">http://i.stack.imgur.com/0Ow7c.png</a>) are basically the same<br>
> in this case. The lines after the text show up black.<br>
><br>
> How do I get the colors to show up in the labels with the default<br>
> interactive backend?<br>
><br>
> Regards,<br>
><br>
> -Joe<br>
_______________________________________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org" target="_blank">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/matplotlib-users</a><br>
</blockquote></div>