>>>>> "Jeff" == Jeff Huang <[EMAIL PROTECTED]> writes:

    Jeff> Is it possible to have gradients in the bar graphs made by
    Jeff> matplotlib? I couldn't find anything about it in the user
    Jeff> guide.

Here is some example code form the mailing list

To: Christopher Barker <[EMAIL PROTECTED]>
Cc: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] graphs
From: John Hunter <[EMAIL PROTECTED]>
Date: Tue, 16 May 2006 15:01:15 -0500
>>>>> "Christopher" == Christopher Barker <[EMAIL PROTECTED]> writes:

    Christopher> That I don't know. The Agg renderer certainly can do
    Christopher> a nice job with gradients, but I don't know if MPL
    Christopher> support that.

You can emulate gradients using matplotlib images -- either with colormaps or
defining your own rgba endpoints for the gradients.  Here's an example
of an axes background gradient

    from pylab import figure, show, nx, cm

    fig = figure()

    xmin, xmax = xlim = 0,2
    ymin, ymax = ylim = -1,1
    ax = fig.add_subplot(111, xlim=xlim, ylim=ylim,
    autoscale_on=False)
    X = [[.6, .6],[.7,.7]]

    ax.imshow(X, interpolation='bicubic', cmap=cm.Blues,
              extent=(xmin, xmax, ymin, ymax), alpha=1)
    t = nx.arange(xmin, xmax,0.01)
    ax.plot(t, nx.sin(2*nx.pi*t), lw=2, color='black')
    show()


Likewise, you can make your own gradient bars charts:

    from pylab import figure, show, nx, cm

    def gbar(ax, x, y, width=0.5, bottom=0):
        X = [[.6, .6],[.7,.7]]
        for left,top in zip(x, y):
            right = left+width
            ax.imshow(X, interpolation='bicubic', cmap=cm.Blues,
                      extent=(left, right, bottom, top), alpha=1)

    fig = figure()

    xmin, xmax = xlim = 0,10
    ymin, ymax = ylim = 0,1
    ax = fig.add_subplot(111, xlim=xlim, ylim=ylim,
                         autoscale_on=False)
    X = [[.6, .6],[.7,.7]]

    ax.imshow(X, interpolation='bicubic', cmap=cm.copper,
              extent=(xmin, xmax, ymin, ymax), alpha=1)

    N = 10
    x = nx.arange(N)+0.25
    y = nx.mlab.rand(N)
    gbar(ax, x, y, width=0.7)
    ax.set_aspect('normal')
    show()

Viewer discretion is advised.

If you want to get clever, you can define patterns and fills this way
too.  We should add an interface to expose this functionality more
readily...

JDH


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to