I am generating some plots using matplotlib and seaborn, and the x-axis and y-axis are different lengths as shown in an example below.
Is there a way to ensure that each axis is of the same scale?
My example code is nothing special, but here is an example:
# plot data
plt.scatter(df['x'], df['y'], color = 'gray', s=5) # s controls point size
plt.xlim(-0.0002,0.002)
plt.ylim(-0.0002,0.002)
# add y=x line
plt.plot([0,1],[0,1], lw=2, color='#414242', linestyle='dashed')
sns.set_context("paper", font_scale=1.5)
plt.xlabel(xlabel, {'size':'20'})
plt.ylabel(ylabel, {'size':'20'})
plt.title(title)
sns.set_style('ticks')
sns.despine(offset=10, trim=True)
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
Using plt.axis('equal')
:
I think you want plt.axis('equal')
, see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With