Along the lines of Mike's suggestion, I thought this could be done using
Latex.


I posted an answer on SO with an example of doing this, but it seems only
to work with postscript backend. Other backends override the color with the
mpl text color setting.

Is there a way to prevent this override? For example don't try to use 'PS'
backend, and look at hte figure interactively. It defaults to black.

http://stackoverflow.com/a/9185143/717357

-Yann



On Tue, Feb 7, 2012 at 4:46 PM, Paul Ivanov <pivanov...@gmail.com> wrote:

> Benjamin Root, on 2012-02-07 13:46,  wrote:
> > Also, how deep should this rabbit hole go?  I could imagine one could
> want
> > this for title() and figtitle().  Maybe it would be best to implement
> this
> > at the Text() constructor level?
>
> For this reason, I would discourage even implementing such
> functionality in the core of matplotlib. This functionality doesn't strike
> me
> as something that ought to be available everywhere by default - if someone
> needs it, they can implement it as follows:
>
> -----
> import matplotlib.pyplot as plt
> from matplotlib import transforms
>
> def rainbow_text(x,y,ls,lc,**kw):
>    """
>    Take a list of strings ``ls`` and colors ``lc`` and place them next to
> each
>    other, with text ls[i] being shown in color lc[i].
>
>    This example shows how to do both vertical and horizontal text, and will
>    pass all keyword arguments to plt.text, so you can set the font size,
>    family, etc.
>    """
>    t = plt.gca().transData
>    fig = plt.gcf()
>    plt.show()
>
>    #horizontal version
>    for s,c in zip(ls,lc):
>        text = plt.text(x,y," "+s+" ",color=c, transform=t, **kw)
>        text.draw(fig.canvas.get_renderer())
>        ex = text.get_window_extent()
>        t = transforms.offset_copy(text._transform, x=ex.width,
> units='dots')
>
>    #vertical version
>    for s,c in zip(ls,lc):
>        text = plt.text(x,y," "+s+" ",color=c, transform=t,
>                rotation=90,va='bottom',ha='center',**kw)
>        text.draw(fig.canvas.get_renderer())
>        ex = text.get_window_extent()
>        t = transforms.offset_copy(text._transform, y=ex.height,
> units='dots')
>
>
> plt.figure()
> rainbow_text(0.5,0.5,"all unicorns poop rainbows ! ! !".split(),
>        ['red', 'orange', 'brown', 'green', 'blue', 'purple', 'black'],
>        size=40)
>
> best,
> --
> Paul Ivanov
> 314 address only used for lists,  off-list direct email at:
> http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7
>
>
> ------------------------------------------------------------------------------
> Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-d2d
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to