0

The topic is not new but up till now all the examples i saw are used for random data and it somehow works with ax.img. However, i couldnt manage to make my code work. I have tried this solution with ImageGrid but i'm not sure how to defined my grid[0] and grid[1] (colorbar changes the size of subplot in python). I thought it supposed to be my first and second contour plot but it is not ... Below is a snippet of it.

X,Y = np.meshgrid(x,y)

fig = plt.figure()
ax1 = fig.add_subplot(121, aspect='equal')
ax2 = fig.add_subplot(122, aspect='equal')
ax1.contourf(X,Y,z1,100,cmap='RdGy') #100 equally spaced intervals within the data range
axs=ax2.contourf(X,Y,z1_90,100,cmap='RdGy')

ax2.set_yticklabels([])
ax1.set_ylabel('Bond length $H_{2}$-$H_{3}$ ($\AA$)')
fig.text(0.5, 0.135, 'Bond length $H_{2}$-$H_{1}$ ($\AA$)', ha='center')
cbar=plt.colorbar(axs,fraction=0.046, pad=0.04,label='E(Hartree)')
plt.tight_layout()

It would be great if you can give me hints how to solve the problem instead of pasting links because I have already googled a lot. As said above, the main problem here is that i have a contourf plot and not some random data ... enter image description here

Jung
  • 145
  • 6
  • Another possibility: https://stackoverflow.com/a/42397467/8881141 – Mr. T Feb 06 '21 at 13:42
  • 1
    Also see the second example in [this tutorial](https://matplotlib.org/3.3.4/gallery/axes_grid1/demo_colorbar_with_inset_locator.html) about how inset axes can be used to place a colorbar without "stealing" space from the subplot. – JohanC Feb 06 '21 at 13:50

0 Answers0