使用python中的自定义轴刻度标签扩展轴限制

问题描述

我正在尝试使用自定义坐标轴刻度标签设置绘图,我希望我的x轴,y轴极限范围相同。在图像中,y轴最大值为31622776,我想将y轴扩展到100000000(与x轴相同)。我使用的代码

ax = sns.scatterplot(x="Actual",y="Predict",hue="Flag",style="Flag",data=df)
x_labels = {31622 : 4.5,100000 : 5,316227 : 5.5,1000000 : 6,3162277 : 6.5,10000000 : 7,31622776 : 7.5,100000000 : 8}     
ax.set_xticklabels(x_labels)
y_labels = {31622 : 4.5,100000000 : 8}
ax.set_yticklabels(y_labels)
plt.title(r'Log-Log plot of Actual Sales Price Vs Predicted Sales Price')
plt.xlabel(r'Actual Sales Price in Dollars')
plt.ylabel(r'Predicted Sales Price in Dollars')

enter image description here

我为实现它应该做出的改变感到困惑。

解决方法

除了设置刻度标签外,还要使用matplotlib.pyplot.xlim()/ .ylim()。刻度标签不会自动更改轴的缩放比例。

请参阅:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.xlim.html