I am trying to color-highlight parts of a figure title. I got it to
work via the second (‘non-interactive’) solution given here ,
using TeX’s \textcolor. It has the advantage (over the first
solution) that you can use .xlabel(), .title() etc. as usual.
However the limitation stated is that it only works when saving the
plot as a PostScript file. I’m finding this to be true: the coloring
does not appear when plotting to the screen rather than to a file
(as with .show()), nor when using matplotlib.use(‘SVG’) or
matplotlib.use(‘AGG’) to get svg or png output (which I would
prefer). This is so even though other ‘fancy’ TeX commands like
\mathcal do seem to work in all output options.
I am only minimally acquainted with (La)TeX, and fairly new to
Python and matplotlib too, so I don’t quite grasp what is going on
here, and whether it is worth digging deeper to try and make it
work. So: why is there a difference in success between using (e.g.)
\mathcal versus \textcolor over different output options?
They give an example for an interactive backend which means it would work with any output format in the link you provided. Could also use \textcolor for .pdf output as well since the text rendering would use TeX as well but this wouldn’t get you SVG.
On Tue, Aug 13, 2013 at 9:00 PM, Xiha <xiha@…878…547…> wrote:
Hello,
I am trying to color-highlight parts of a figure title. I got it to
work via the second (‘non-interactive’) solution given here ,
using TeX’s \textcolor. It has the advantage (over the first
solution) that you can use .xlabel(), .title() etc. as usual.
However the limitation stated is that it only works when saving the
plot as a PostScript file. I’m finding this to be true: the coloring
does not appear when plotting to the screen rather than to a file
(as with .show()), nor when using matplotlib.use(‘SVG’) or
matplotlib.use(‘AGG’) to get svg or png output (which I would
prefer). This is so even though other ‘fancy’ TeX commands like
\mathcal do seem to work in all output options.
I am only minimally acquainted with (La)TeX, and fairly new to
Python and matplotlib too, so I don’t quite grasp what is going on
here, and whether it is worth digging deeper to try and make it
work. So: why is there a difference in success between using (e.g.)
\mathcal versus \textcolor over different output options?
Many thanks!
``
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It’s a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
Thanks Jeffrey. That clarifies why \mathcal works everywhere: it's handled by matplotlib's own parser. In contrast, for \textcolor, a call to TeX via the lines
from matplotlib import rc
rc('text', usetex=True)
rc('text.latex', preamble='\usepackage{color}')
is necessary.
I still don't get \texcolor to work for anything other than ps. This is inconvenient as I'm not used to PostScript; for one thing, when I need the plot to be 'big' [using plt.figure(figsize=(13.0, 13.0))], the ps file created seems to be an A4 format with the plot not fitting onto it: it is shown only partially. In contrast, for pdf or svg output, the page size is adapted to the figure size -- but in those cases \textcolor does not work...
···
On Wed 14 Aug 2013 03:34:13 CEST, Jeffrey Spencer wrote:
Have a look here why Mathcal works in all backends:
They give an example for an interactive backend which means it would
work with any output format in the link you provided. Could also use
\textcolor for .pdf output as well since the text rendering would use
TeX as well but this wouldn't get you SVG.
On Tue, Aug 13, 2013 at 9:00 PM, Xiha <xiha@...547... > <mailto:xiha@…547…>> wrote:
Hello,
I am trying to color-highlight parts of a figure title. I got it
to work via the second ('non-interactive') solution given here
<python - Partial coloring of text - Stack Overflow,
using TeX's \textcolor. It has the advantage (over the first
solution) that you can use .xlabel(), .title() etc. as usual.
However the limitation stated is that it only works when saving
the plot as a PostScript file. I'm finding this to be true: the
coloring does not appear when plotting to the screen rather than
to a file (as with .show()), nor when using matplotlib.use('SVG')
or matplotlib.use('AGG') to get svg or png output (which I would
prefer). This is so even though other 'fancy' TeX commands like
\mathcal do seem to work in all output options.
I am only minimally acquainted with (La)TeX, and fairly new to
Python and matplotlib too, so I don't quite grasp what is going on
here, and whether it is worth digging deeper to try and make it
work. So: why is there a difference in success between using
(e.g.) \mathcal versus \textcolor over different output options?
Many thanks!
>>
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes. http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
<mailto:Matplotlib-users@lists.sourceforge.net> matplotlib-users List Signup and Options
The .tex parser for matplotlib uses dvi files that when converted to be used in a pdf or other backends lose their color information is my guess. If you output a ps file (or an eps file which you might want to do so you don’t have to set the page size). Then run epstopdf or pstopdf the color is striped from the file as well. I don’t know enough about the actual mechanisms to provide much more information then this but hope that helps.
···
On Wed, Aug 14, 2013 at 8:50 PM, Xiha <xiha@…547…> wrote:
Thanks Jeffrey. That clarifies why \mathcal works everywhere: it’s handled by matplotlib’s own parser. In contrast, for \textcolor, a call to TeX via the lines
from matplotlib import rc
rc(‘text’, usetex=True)
rc(‘text.latex’, preamble=‘\usepackage{color}’)
is necessary.
I still don’t get \texcolor to work for anything other than ps. This is inconvenient as I’m not used to PostScript; for one thing, when I need the plot to be ‘big’ [using plt.figure(figsize=(13.0, 13.0))], the ps file created seems to be an A4 format with the plot not fitting onto it: it is shown only partially. In contrast, for pdf or svg output, the page size is adapted to the figure size – but in those cases \textcolor does not work…
On Wed 14 Aug 2013 03:34:13 CEST, Jeffrey Spencer wrote:
Have a look here why Mathcal works in all backends:
using TeX's \textcolor. It has the advantage (over the first
solution) that you can use .xlabel(), .title() etc. as usual.
However the limitation stated is that it only works when saving
the plot as a PostScript file. I'm finding this to be true: the
coloring does not appear when plotting to the screen rather than
to a file (as with .show()), nor when using matplotlib.use('SVG')
or matplotlib.use('AGG') to get svg or png output (which I would
prefer). This is so even though other 'fancy' TeX commands like
\mathcal do seem to work in all output options.
I am only minimally acquainted with (La)TeX, and fairly new to
Python and matplotlib too, so I don't quite grasp what is going on
here, and whether it is worth digging deeper to try and make it
work. So: why is there a difference in success between using
(e.g.) \mathcal versus \textcolor over different output options?
Many thanks!
||
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
[http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk](http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk)
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...1735...sourceforge.net
Forgot to mention. I normally use epstopdf to convert eps files to pdf files and the color information is stripped from the pdf file when embedded with the color or xcolor packages from within matplotlib. But if you use, epspdf or epspdftk on linux you can retain color information when converting eps files to pdf files so can try that as an option.
···
On Wed, Aug 14, 2013 at 8:50 PM, Xiha <xiha@…547…> wrote:
Thanks Jeffrey. That clarifies why \mathcal works everywhere: it’s handled by matplotlib’s own parser. In contrast, for \textcolor, a call to TeX via the lines
from matplotlib import rc
rc(‘text’, usetex=True)
rc(‘text.latex’, preamble=‘\usepackage{color}’)
is necessary.
I still don’t get \texcolor to work for anything other than ps. This is inconvenient as I’m not used to PostScript; for one thing, when I need the plot to be ‘big’ [using plt.figure(figsize=(13.0, 13.0))], the ps file created seems to be an A4 format with the plot not fitting onto it: it is shown only partially. In contrast, for pdf or svg output, the page size is adapted to the figure size – but in those cases \textcolor does not work…
On Wed 14 Aug 2013 03:34:13 CEST, Jeffrey Spencer wrote:
Have a look here why Mathcal works in all backends:
using TeX's \textcolor. It has the advantage (over the first
solution) that you can use .xlabel(), .title() etc. as usual.
However the limitation stated is that it only works when saving
the plot as a PostScript file. I'm finding this to be true: the
coloring does not appear when plotting to the screen rather than
to a file (as with .show()), nor when using matplotlib.use('SVG')
or matplotlib.use('AGG') to get svg or png output (which I would
prefer). This is so even though other 'fancy' TeX commands like
\mathcal do seem to work in all output options.
I am only minimally acquainted with (La)TeX, and fairly new to
Python and matplotlib too, so I don't quite grasp what is going on
here, and whether it is worth digging deeper to try and make it
work. So: why is there a difference in success between using
(e.g.) \mathcal versus \textcolor over different output options?
Many thanks!
||
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
[http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk](http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk)
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...1735...sourceforge.net