【问题标题】:Attaching multiple plots to a seaborn plot将多个地块附加到 seaborn 地块
【发布时间】:2016-06-18 18:44:11
【问题描述】:

以下代码:

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

生成如下图片:

但是,我想另外绘制一对与散点图的上限和下限相对应的线。为此,我需要在现有图的顶部绘制这些线。

最好的方法是什么?

【问题讨论】:

    标签: python matplotlib data-visualization seaborn


    【解决方案1】:

    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])
    

    给予:

    【讨论】:

      猜你喜欢
      • 2021-09-30
      • 2019-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      • 2014-12-23
      • 2019-12-23
      相关资源
      最近更新 更多