python matplotlib绘图怎么让每个柱面颜色不一样?

查看:582
本文介绍了python matplotlib绘图怎么让每个柱面颜色不一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

def huitu_host(nodes,total):
    x = np.arange(len(nodes))
    plt.figure(figsize=(9,5))
    plt.xticks(x,nodes)
    plt.bar(x,total,width = 0.5,facecolor = 'yellowgreen',edgecolor = 'white')
    for x,y in zip(x,total):
        plt.text(x,y,'%.f' % y,ha="center", va="bottom")
    plt.show()
    return

解决方案

coloredgecolor这些都能传array-like的参数
在array里分别指定颜色就好了
例子:

x=np.arange(10)
y=np.arange(10)
plt.bar(x,y,color=['red','green'])

这篇关于python matplotlib绘图怎么让每个柱面颜色不一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆