【问题标题】:how do I plot two seaborn plots using subplots?如何使用子图绘制两个 seaborn 图?
【发布时间】:2020-05-23 19:38:09
【问题描述】:

我正在尝试以 seaborn 风格并排绘制两个系列,但这不起作用:

fig, (ax1, ax2) = plt.subplots(ncols = 2, nrows = 1, figsize = (15,5))
ax1 = sns.distplot(data_1['Mileage'])
ax2 = sns.distplot(data_2['Mileage'])

似乎在 ax2 子图中同时绘制了 ax1 和 ax2。有谁知道怎么做?

谢谢!

【问题讨论】:

    标签: pandas matplotlib seaborn


    【解决方案1】:

    在绘图时将单独的子图 ax1ax2 传递给 ax 参数。 documentation 也说明了这一点。

    sns.distplot(data_1['Mileage'], ax=ax1) # <--- ax1 passed here
    sns.distplot(data_2['Mileage'], ax=ax2) # <--- ax2 passed here
    

    【讨论】:

      猜你喜欢
      • 2018-12-09
      • 1970-01-01
      • 2019-11-28
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 2016-05-04
      • 1970-01-01
      • 2015-09-23
      相关资源
      最近更新 更多