python - Colorbars close to subplots -


how can put colorbars beside each colormap in subplot? simplified version of real code here shows problem. can see colorbars @ bottom right , making last plot smaller.

from matplotlib import pyplot plt import numpy np def plots():     fig,ax=plt.subplots(2,2)     in range(2):             rho_mat,c_mat=np.random.uniform(size=(50,50)),np.random.uniform(size=(50,50))         ax[0,i].set_title(r"$\rho_{x,y}$")                 p=ax[0,i].imshow(np.fliplr(rho_mat).t,extent=[0.,1,0.,1],vmin=0,vmax=1, interpolation='none')             ax[0,i].set_xlabel(r'$\epsilon_1$')         ax[0,i].set_ylabel(r'$\epsilon_2$')         fig.colorbar(p, shrink=0.5)         ax[1,i].set_title(r"$c_{x,y}$")         p2=ax[1,i].imshow(np.fliplr(c_mat).t,extent=[0.,1,0.,1],vmin=0,vmax=1, interpolation='none')         ax[1,i].set_xlabel(r'$\epsilon_1$')         ax[1,i].set_ylabel(r'$\epsilon_2$')         fig.colorbar(p2, shrink=0.5)         plt.tight_layout()     plt.show() plots() 

enter image description here

the colorbar method has optional keyword argument allows specify axes associated with.

in code change call colorbar this:

fig.colorbar(p, ax=ax[0,i], shrink=0.5) fig.colorbar(p2, ax=ax[1,i],  shrink=0.5) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -