Use the same colorbar for different subplots in matplotlib

前端 未结 1 1353
借酒劲吻你
借酒劲吻你 2021-01-05 14:47

I am plotting different figure in subplots using the following procedure.

fig = figure(figsize=(10,11))
subplots_adjust(wspace=0.5,hspace=0.2)
iplot = 330
fo         


        
相关标签:
1条回答
  • 2021-01-05 15:30

    Look at the example below:

    import matplotlib.pyplot as plt
    
    fig, axes = plt.subplots(nrows=3, ncols=3)
    for ax in axes.flat:
        im = ax.imshow(np.random.random((6,6)), interpolation='nearest', cmap='gnuplot',
         vmin=0, vmax=1, extent=[0.05,0.5,1,0.05],aspect=0.5)
    
    fig.subplots_adjust(right=0.8)
    # put colorbar at desire position
    cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7])
    fig.colorbar(im, cax=cbar_ax)
    
    plt.show()
    

    0 讨论(0)
提交回复
热议问题