python - 具有相同 Y 轴刻度的 Seaborn Reg 图(并排)
问题描述
我在 seaborn 有两个 reg 地块
sb.regplot(x="V", y="Matrix Time", data = df_1, scatter_kws={"color": "b"}, line_kws={"color": "red"})
sb.regplot(x="V", y="List Time", data = df_1, scatter_kws={"color": "g"}, line_kws={"color": "red"})
我想在 Y 轴上以相同的比例并排显示这些图。如果有人可以帮助我,我将不胜感激。
编辑:我尝试使用
fig, ax = plt.subplots(1,2, figsize=(16,8))
sb.regplot(x="V", y="Matrix Time", data=df_1, ax=ax[0], scatter_kws={"color": "b"}, line_kws={"color": "red"})
sb.regplot(x="V", y="List Time", data=df_1, ax=ax[1], scatter_kws={"color": "g"}, line_kws={"color": "red"})
虽然它确实给了我两张相同大小的图表。每个图表的 Y 轴比例不同。
https://i.stack.imgur.com/xkIUO.png
我希望将两个图形并排放置,以使每个图形的 Y 轴上的值处于相同的水平水平。像这样:https ://i.stack.imgur.com/28iko.png
(我通过在 powerpoint 中截取每个图形的屏幕截图并调整大小以使 y 轴值处于同一水平来创建上面的图像)
解决方案
在您的代码中,您需要编写:
sb.regplot(x="V", y="Matrix Time", data = df_1, scatter_kws={"color": "b"}, line_kws={"color": "red"}, ax=ax[0])
sb.regplot(x="V", y="List Time", data = df_1, scatter_kws={"color": "g"}, line_kws={"color": "red"}, ax=ax[1])
对于您编辑的问题,您需要plt.subplots(..., sharey=True)
. 我写的例子:
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
fig, ax =plt.subplots(1,2, sharey=True)
sns.regplot(x="total_bill", y="tip", data=tips, ax=ax[0])
sns.regplot(x="total_bill", y="tip", data=tips.loc[:10], ax=ax[1])
fig.show()
输出:
推荐阅读
- android - 线程“main”中的异常 java.lang.UnsupportedClassVersionError - 在 android 中使用 BundleTool 提取包 apk 时
- pandas - Pandas groupby 对每个组的值进行排序,并根据每个组的最大值对数据框组进行排序
- java - 从 HTML 文本中获取特定值
- pandas - 彼此相邻绘制直方图
- excel - Excel 每新一周将索引递增 1
- firebase - 如何检查文件名是否包含 Firebase 存储安全规则中的 uid?
- django - 具有不同路径的 django 静态文件
- android - java.io.ioexception 连接改造android上的流意外结束
- terraform - Terraform 在导入当前状态后询问“ami”和“instance_type”
- azure - 无法在 terraform azure 提供程序中获取 SystemAssigned 身份属性