user11339690
user11339690

Reputation:

Set aspect ratio on semi-log subplots

I am trying to produce a figure with a total of 12 subplots. The x-axis is log, and the y axis is linear. How do I set the aspect ratio for each to 1?

plt.subplot(6, 2, 4)
plt.plot(H2SO3,h_km, label='H$_2$SO$_3$')
plt.xscale('log')
plt.xlim(10**-16)
plt.legend()

plt.subplot(6, 2, 11)
plt.plot(H2S,h_km, label='H$_2$S')
plt.xscale('log')
plt.xlim(10**-16)


plt.savefig('heelp.png')
plt.show()

I've only found solutions to loglog or linearlinear plots, so any help would be greatly appreciated, thanks!

Upvotes: 0

Views: 675

Answers (1)

J B
J B

Reputation: 440

You'll need to set or obtain both xlimits on the log scale, then use the log10 of the ratio of those limits to get the 'length' of the log axis which is analagous to the simple difference on a linear scale, and then further take the ratio of the two lengths.

ax = plt.subplot(6, 2, 4)
ax.plot(H2SO3,h_km, label='H$_2$SO$_3$')
plt.xscale('log')
plt.xlim(10**-18,10**-16)
plt.ylim(5,15) # for eg
plt.legend()
ax.set_aspect( np.log10(10**-16/10**-18) / (15-5) )

Upvotes: 1

Related Questions