我正在使用 matplotlib 和 seaborn 生成一些图,x 轴和 y 轴的长度不同,如下面的示例所示。
有没有办法确保每个轴的比例相同?
我的示例代码没什么特别的,但这是一个示例:
# 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()
Run Code Online (Sandbox Code Playgroud)
使用plt.axis('equal')
: