matplotlib - Python - add colorbars in multiple plots for each plot -
i have multiple plots on figure. add colorbars each results. these colorbars must have same height of results , limit numbers displayed on colorbar 3 values (in order have readable figures).
my code :
fig, axes = plt.subplots(nrows=1, ncols=3) plt.tight_layout(pad=0.5, w_pad=2.5, h_pad=2.0) ax1 = plt.subplot(131) # creates first axis ax1.set_xticks([0,2000,500,1000,1500]) ax1.set_yticks([0,2000,500,1000,1500]) ax1.imshow(u,cmap='hot',extent=(x.min(),2000,y.min(),2000)) ax1.set_title("$ \mathrm{ux_{mes} \/ (pix)}$") ax2 = plt.subplot(132) # creates second axis ax2.set_xticks([0,2000,500,1000,1500]) ax2.set_yticks([0,2000,500,1000,1500]) ax2.imshow(uu,cmap='hot',extent=(x.min(),2000,y.min(),2000)) ax2.set_title("$\mathrm{ux_{cal} \/ (pix)}$") ax3 = plt.subplot(133) # creates first axis ax3.set_xticks([0,2000,500,1000,1500]) ax3.set_yticks([0,2000,500,1000,1500]) ax3.imshow(resu,cmap='hot',extent=(x.min(),2000,y.min(),2000)) ax3.set_title("$\mathrm{\mid ux - ux \mid \/ (pix)}$ ") plt.show()
i try add : "fig.colorbar(u, axes=ax1,fraction=0.046, pad=0.04)" doesnt work...
following answer @plonser,
tick = np.linspace(min(your_variable),max(your_variable),3) plt.tight_layout(pad=0.5, w_pad=2.5, h_pad=2.0) ax1 = plt.subplot(131) # creates first axis ax1.set_xticks([0,2000,500,1000,1500]) ax1.set_yticks([0,2000,500,1000,1500]) i1 = ax1.imshow(u,cmap='hot',extent=(x.min(),2000,y.min(),2000)) plt.colorbar(i1,ax=ax1,ticks=tick) ax1.set_title("$ \mathrm{ux_{mes} \/ (pix)}$") ax2 = plt.subplot(132) # creates second axis ax2.set_xticks([0,2000,500,1000,1500]) ax2.set_yticks([0,2000,500,1000,1500]) i2=ax2.imshow(uu,cmap='hot',extent=(x.min(),2000,y.min(),2000)) ax2.set_title("$\mathrm{ux_{cal} \/ (pix)}$") plt.colorbar(i2,ax=ax2,ticks=tick) ax3 = plt.subplot(133) # creates first axis ax3.set_xticks([0,2000,500,1000,1500]) ax3.set_yticks([0,2000,500,1000,1500]) i3 = ax3.imshow(resu,cmap='hot',extent=(x.min(),2000,y.min(),2000)) ax3.set_title("$\mathrm{\mid ux - ux \mid \/ (pix)}$ ") plt.colorbar(i3,ax=ax3,ticks=tick) plt.show()
when specify, using ax=ax1
, not axes=ax1
. limit number of items in colorbar
, can using ticks
option.
Comments
Post a Comment