将多个图附加到seaborn p

2024-04-26 03:41:30 发布

您现在位置:Python中文网/ 问答频道 /正文

以下代码:

import seaborn as sns
sns.lmplot(x='EstCurentMarketValueSqFt',
           y='MarketValueSqFt',
           data=sales,
           scatter_kws={'edgecolor': "black",
                        'linewidth': 1})

生成以下图片:

enter image description here

另外,我想用一对下界的散点线来对应。要做到这一点,我需要在现有的图上绘制这些线。在

最好的办法是什么?在


Tags: 代码importdataasseabornblacksalessns
1条回答
网友
1楼 · 发布于 2024-04-26 03:41:30

sns.lmplot不会立即与matplotlib方法交互(至少,不像我习惯的那样),因为它附加到sns.FacetGrid。在

在进一步阅读API之后,建议使用regplot。这很管用:

f, ax = plt.subplots(figsize=(12, 12))
ax.set_xlim([0, 5000])
ax.set_ylim([0, 5000])
sns.regplot(x='EstCurentMarketValueSqFt',
           y='MarketValueSqFt',
           data=sales,
           scatter_kws={'edgecolor': "white",
                        'linewidth': 1},
          )
plt.plot([1, 5000], [1, 500])
plt.plot([1, 500], [1, 5000])

给出:

enter image description here

相关问题 更多 >