How to update barchart in matplotlib?

后端 未结 1 1061
我在风中等你
我在风中等你 2021-01-19 00:08

I have bar chart, with a lot of custom properties ( label, linewidth, edgecolor)

import matplotlib.pyplot as plt
fig = plt.figure()
ax  = plt.gca()

x = np.a         


        
相关标签:
1条回答
  • 2021-01-19 00:28

    In your case, bars is only a BarContainer, which is basically a list of Rectangle patches. To just remove those while keeping all other properties of ax, you can loop over the bars container and call remove on all its entries or as ImportanceOfBeingErnest pointed out simply remove the full container:

    import numpy as np
    import matplotlib.pyplot as plt
    fig = plt.figure()
    ax  = plt.gca()
    
    x = np.arange(5)
    y = np.random.rand(5)
    
    bars = ax.bar(x, y, color='grey', linewidth=4.0)
    
    bars.remove()
    x2 = np.arange(10)
    y2 = np.random.rand(10)
    ax.bar(x2,y2)
    plt.show()
    
    0 讨论(0)
提交回复
热议问题