python - Seaborn relplot 子图轴限制
问题描述
这是我在 Stackoverflow 上的第一个问题!
我一直在用 seaborn 绘制一些散点图relplot()
。对于我的前两张图,子图的大小和它们的 x 轴看起来很正常。但是在我的第三个情节中,我得到了这样的东西
你可以看到 x 轴只有 2 个从 0 到 1 的刻度,我想让它们与 y 轴相同。这是我的代码:
#Setting style
sns.set_style('ticks')
sns.set_palette('RdBu',6)
plt.figure(figsize=(10,8))
#Plotting
rel = sns.relplot(data=df_scenarios, x="feb_pred",
y="mar_pred", col="scenarios", col_wrap=2,
kind="scatter", hue="pred_diff")
#Customizing
rel.set(xlabel="202002 pred", ylabel = "202003 pred")
a0 = rel.fig.axes[0]
a0.set_title("scen1")
a0.plot([0,1],[0,1],'black',linewidth = 2 )
a1 = rel.fig.axes[1]
a1.set_title("scen2")
a1.plot([0,1],[0,1],'black',linewidth = 2 )
a2 = rel.fig.axes[2]
a2.set_title("scen3")
a2.plot([0,1],[0,1],'black',linewidth = 2 )
a3 = rel.fig.axes[3]
a3.set_title("scen4")
a3.plot([0,1],[0,1],'black',linewidth = 2 )
a4 = rel.fig.axes[4]
a4.set_title("scen5")
a4.plot([0,1],[0,1],'black',linewidth = 2 )
a5 = rel.fig.axes[5]
a5.set_title("scen6")
a5.plot([0,1],[0,1],'black',linewidth = 2 )
plt.show()
有谁知道我可以改变什么以使 x 和 y 轴具有相同的刻度?
谢谢!
解决方案
欢迎来到 Stackoverflow!您可以将此添加到您的绘图自定义中,以强制 x 限制等于 y 限制并使每个子图二次:
for ax in rel.fig.axes:
ax.set_xlim(ax.get_ylim())
ax.set_aspect('equal')
您可能还想更改图形大小以适应 2x3 格式。
推荐阅读
- ios - 循环 AnyHashable 字典
- python - Python 和 Excel 公式
- java - Apache Avro Parquet java.lang.NoSuchFieldError: NULL_VALUE
- c# - c#无法将文本附加到现有文件
- c++ - 在OpenCV中将二维码投影到摄像头时,出现错误
- java - 与 JIB Gradle 集成导致编译错误
- reactjs - 如何将 pdf 文件/blob 上传到 S3?
- html - 如何在表格中的悬停元素上实现水平和垂直悬停效果:如何创建相交悬停?
- java - 将 $addToSet 与 Spring Batch MongoItemWriter 一起使用
- python - 从托管的 django 站点连接 ZKTECO 设备出现错误