0
votes

I would like to plot 2 subplots in the same row with the same aspect ratio. It's quite ugly otherwise !

So, usually, I'm using axes().set_aspect('equal') (because I want ALSO to remove the axis, and I can't use 'off' AND 'equal') from pylab but it doesn't work right here, only the 2nd picture appears

My code:

plt.subplot(1,2,1)
axes().set_aspect('equal')
plt.tricontourf(x_exp, y_exp, z_exp)
plt.colorbar(shrink=0.9,drawedges=True, orientation='vertical')
plt.axis('off')
plt.title('tricontour')

plt.subplot(1,2,2)
axes().set_aspect('equal')
plt.tricontourf(x_exp, y_exp, z_exp2)
plt.colorbar(shrink=0.9,drawedges=True, orientation='vertical')
plt.axis('off')
plt.title('tricontour')

plt.show()

It could probably work with the following line but subplot doesn't have the tricontourf plot !

fig = plt.figure() ax1 = fig.add_subplot(2,1,1, adjustable='box', aspect=0.3) ax2 = fig.add_subplot(2,1,2)

Do you have an idea to figure out that ?

EDIT: Sample of data

I have used np.savez("Sample",x_exp=x_exp,y_exp=y_exp,z_exp=z_exp,z_exp2=z_exp2)to save the data.

You can read it with the following lines:

import numpy as np
Data = np.load("Sample.npz")
x_exp = Data['x_exp']
y_exp = Data['y_exp']
z_exp = Data['z_exp']
z_exp2 = Data['z_exp2']
2
could you post a sample of x_exp, y_exp, z_exp and z_exp2?Julien Spronck
Sure. I'm trying to figure out how, 1sec.Lmecano
let me know if my answer below is what you are afterJulien Spronck

2 Answers

3
votes

I think this should do what you want. I define each axes as subplots of the figure and change their properties to get an equal aspect ratio and to turn them off:

fig = plt.figure()

ax1 = fig.add_subplot(1,2,1)
im = ax1.tricontourf(x_exp, y_exp, z_exp)
plt.colorbar(im, drawedges=True, orientation='vertical')
ax1.set_aspect('equal')
ax1.set_axis_off()
ax1.set_title('tricontour')

ax2 = fig.add_subplot(1,2,2)
im = ax2.tricontourf(x_exp, y_exp, z_exp2)
plt.colorbar(im, drawedges=True, orientation='vertical')
ax2.set_aspect('equal')
ax2.set_axis_off()
ax2.set_title('tricontour')

plt.show()
1
votes

I was looking for the same functionality. You can set aspect ratio of all the subplots by passing subplots_kw=dict(<kw arguments for plt.axes>)

For example,

fig, axs = plt.subplots(2, 3, subplot_kw=dict(box_aspect=1))