Home  >  Q&A  >  body text

How to make each cylinder color different in python matplotlib drawing?

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

大家讲道理大家讲道理2712 days ago643

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-05-18 10:52:43

    coloredgecolorThese can all be passed array-like parameters
    Just specify the colors in the array respectively
    Example:

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

    reply
    0
  • Cancelreply