SourceForge logo
SourceForge logo
Menu

matplotlib-devel

From: Michael G. <mic...@gm...> - 2011年08月27日 21:16:20
Hi,
I'm trying to generate colored text on my plots, but can only seem
to get black and white. I've attached an example python scriptx
(test.py) that demonstrates the problem. This produces a plot
(test.png) with black and white text even though I've explicitly told
latex to use color, and in fact the intermediate image gets colored
correctly (attached 25a9904ac88febf5f01477f069213537.png file taken
from .matplotlib/tex.cache). I'm currently using matplotlib 0.99.3.
Thanks for any help with this issue.
Note that I'm not subscribed to this list, so please CC me on replies.
Best wishes,
Mike
From: John H. <jd...@gm...> - 2011年09月01日 01:49:46
On Sat, Aug 27, 2011 at 4:15 PM, Michael Gilbert
<mic...@gm...> wrote:
> Hi,
>
> I'm trying to generate colored text on my plots, but  can only seem
> to get black and white. I've attached an example python scriptx
> (test.py) that demonstrates the problem. This produces a plot
> (test.png) with black and white text even though I've explicitly told
> latex to use color, and in fact the intermediate image gets colored
> correctly (attached 25a9904ac88febf5f01477f069213537.png file taken
> from .matplotlib/tex.cache). I'm currently using matplotlib 0.99.3.
> Thanks for any help with this issue.
>
> Note that I'm not subscribed to this list, so please CC me on replies.
That won't work because mpl converts all tex png raster to black and
white and handles color on its own in post-processing. The following
does work:
import numpy , pylab
x = numpy.arange( 0.0 , 5.0 )
pylab.rc( 'text' , usetex=True )
pylab.title( r'$\rm{colored\ title\ wanted}$', color='blue' )
pylab.plot( x )
pylab.savefig( 'test.png' )
pylab.show()
>
> Best wishes,
> Mike
>
> ------------------------------------------------------------------------------
> Special Offer -- Download ArcSight Logger for FREE!
> Finally, a world-class log management solution at an even better
> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
> download Logger. Secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsisghtdev2dev
> _______________________________________________
> Matplotlib-devel mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>
>
From: John H. <jd...@gm...> - 2011年09月01日 01:53:02
On Wed, Aug 31, 2011 at 8:49 PM, John Hunter <jd...@gm...> wrote:
>> Note that I'm not subscribed to this list, so please CC me on replies.
>
> That won't work because mpl converts all tex png raster to black and
> white and handles color on its own in post-processing. The following
> does work:
>
> import numpy , pylab
>
> x = numpy.arange( 0.0 , 5.0 )
> pylab.rc( 'text' , usetex=True )
> pylab.title( r'$\rm{colored\ title\ wanted}$', color='blue' )
> pylab.plot( x )
> pylab.savefig( 'test.png' )
> pylab.show()
But since you set usetex, you shouldn't need the $ escapes and the
literal rm font. It should be enough to do:
pylab.title( r'colored title wanted 2.5', color='blue' )\
JDH
From: Michael G. <mic...@gm...> - 2011年09月02日 01:04:32
John Hunter wrote:
> On Wed, Aug 31, 2011 at 8:49 PM, John Hunter <jd...@gm...> wrote:
> 
> >> Note that I'm not subscribed to this list, so please CC me on replies.
> >
> > That won't work because mpl converts all tex png raster to black and
> > white and handles color on its own in post-processing. The following
> > does work:
[...]
> But since you set usetex, you shouldn't need the $ escapes and the
> literal rm font. It should be enough to do:
> 
> pylab.title( r'colored title wanted 2.5', color='blue' )\
Hi,
Thanks for the insight. What I'm really trying to get is multiple
colors in the title text. For example, if mpl didn't convert all text
to black, I would want the following to produce blue and red text:
 pylab.rc( 'text' , usetex=True )
 pylab.rc( 'text.latex' , preamble='\usepackage[usenames]{color}' )
 pylab.title( '\\textcolor{Blue}{blue part} \\textcolor{Red}{red part}')
Is there a particular reason why mpl has to convert png colored text
to black and white?
Best wishes,
Mike
From: Michael D. <md...@st...> - 2011年09月06日 16:35:44
On 09/01/2011 09:10 PM, Michael Gilbert wrote:
> John Hunter wrote:
>
>> On Wed, Aug 31, 2011 at 8:49 PM, John Hunter<jd...@gm...> wrote:
>>
>>>> Note that I'm not subscribed to this list, so please CC me on replies.
>>> That won't work because mpl converts all tex png raster to black and
>>> white and handles color on its own in post-processing. The following
>>> does work:
> [...]
>> But since you set usetex, you shouldn't need the $ escapes and the
>> literal rm font. It should be enough to do:
>>
>> pylab.title( r'colored title wanted 2.5', color='blue' )\
> Hi,
>
> Thanks for the insight. What I'm really trying to get is multiple
> colors in the title text. For example, if mpl didn't convert all text
> to black, I would want the following to produce blue and red text:
>
> pylab.rc( 'text' , usetex=True )
> pylab.rc( 'text.latex' , preamble='\usepackage[usenames]{color}' )
> pylab.title( '\\textcolor{Blue}{blue part} \\textcolor{Red}{red part}')
>
> Is there a particular reason why mpl has to convert png colored text
> to black and white?
It works that way so that colored text can be specified by matplotlib 
rather than in LaTeX, therefore the color of text doesn't change based 
on the value of text.usetex. Matplotlib itself doesn't support 
multi-colored text in its own simple text layout algorithm. It's 
probably possible to add an rcParam that would change the behavior to 
get the full color text from LaTeX and use that, but I don't think that 
should be the default behavior.
Mike
-- 
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /