remove colorbar from figure in matplotlib

后端 未结 9 572
终归单人心
终归单人心 2020-12-08 14:14

This should be easy but I\'m having a hard time with it. Basically, I have a subplot in matplotlib that I\'m drawing a hexbin plot in every time a function is called, but ev

9条回答
  •  醉酒成梦
    2020-12-08 15:00

    I managed to solve the same issue using fig.clear() and display.clear_output()

    import matplotlib.pyplot as plt
    import IPython.display as display
    import matplotlib.tri as tri
    from pylab import *
    %matplotlib inline
    
    def plot_res(fig):
        ax=fig.add_axes([0,0,1,1])
        ax.set_xlabel("x")
        ax.set_ylabel('y')
        plotted=ax.imshow(rand(250, 250))
        ax.set_title("title")
        cbar=fig.colorbar(mappable=plotted)
        display.clear_output(wait=True)
        display.display(plt.gcf())
        fig.clear()
    
    fig=plt.figure()
    N=20
    for j in range(N):
        plot_res(fig)
    

提交回复
热议问题