简体   繁体   中英

“shaded” horizontal bars in matplotlib

I'm using a bar plot like this http://matplotlib.org/examples/pylab_examples/barchart_demo2.html

and I'd like to change the way the bars look, eg giving some three-dimensionality look to the bars. What I have in mind is something like this: http://tinyurl.com/oczlafw

Only, I don't know where to start. Maybe repeating the same image along the bar?

Thanks for the help AC

This post on the Matplotlib users list shows how to use a color gradient in a bar chart. This might be similar to what you want. Below I've adapted it for horizontal bars. You might also take a look at this example of using images in bar charts.

from pylab import figure, show, np, cm, hold

def gbar(ax, x, y, height=0.5, left=0):
    X = [[.7, .7],[.6,.6]]
    for right,bottom in zip(x, y):
        top = bottom+height
        print bottom
        print top
        print ''
        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)
hold(True)
X = [[.6, .6],[.7,.7]]

N = 10
y = np.arange(N)+0.25
x = 10*np.random.rand(N)
gbar(ax, x, y)
ax.set_aspect('normal')
ax.set_ylim([0,10])
show()

水平条形图与渐变颜色

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM