0

Im trying to plot 3 figures to compare results. To do this, I'm using the fig.add_subplot() approach as shown in my code snippe:

fig = plt.figure()
ax1 = fig.add_subplot(131, adjustable='box')
ax2 = fig.add_subplot(132, adjustable='box')
ax3 = fig.add_subplot(133, adjustable='box')
rand = np.random.rand(4, 4)

ax1.set_title('image 1')
ax1.set_xlabel('z [m]')
ax1.set_ylabel('y [m]')
ax1.pcolor(rand)
ax2.set_title('image 2')
ax2.set_xlabel('z [m]')
ax2.set_ylabel('y [m]')
ax2.pcolor(rand)

caxes = ax3.pcolor(rand, cmap='viridis')
ax3.set_title('deformed by colorbar')
ax3.set_xlabel('x in m')
ax3.set_ylabel('y in m')
cbar = plt.colorbar(caxes, ax=ax3)
cbar.set_label('color bar')
plt.axis('scaled')
plt.show()

This code output the following plot: enter image description here

I would like to know how to avoid this colour bar deformation by using the fig.add_subplot() approach. I tried to implement this approach that I found in stack overflow, but when I moved the colour bar to an extra Axis I could not reshape it correctly using my subplot approach (i.e. my code).

Desperate Morty
  • 56
  • 2
  • 10

0 Answers0