【问题标题】:Gain plot using seaborn - matplotlib使用 seaborn 获得绘图 - matplotlib
【发布时间】:2021-05-12 00:50:20
【问题描述】:

我正在根据Matplotlib 中的以下示例数据生成增益图。

M_GRP_1      F_GRP_1    GRP_1       GAIN_GRP_1
0.036796    0.067024    0.058878    0.624948
0.000093    0.000087    0.000089    1.043674
0.000316    0.0002      0.000231    1.366149
0.011152    0.008329    0.00909      1.226813
0.001227    0.000747    0.000876    1.400792



import matplotlib.pyplot as plt
import numpy as np 
fig, ax = plt.subplots()
fig.set_size_inches([18, 9])
ax.plot(np.linspace(0,1),np.linspace(0,1), color = 'black', linewidth = 2)
D = d.sort_values('GRP_1', ascending = False).cumsum() 
ax.plot(D.iloc[:,2], D.iloc[:,0], color = 'orange', linewidth = 2)
plt.xlabel('Percentage of total data')
plt.ylabel('Gain')
plt.title ('Target groups :: GRP_1')
plt.legend(['Basline','Male'])
plt.grid(True)
plt.show()

但是,我想使用seaborn 生成相同的图。我想知道如何做到这一点,因为我不熟悉它。

任何机构都可以对此提出建议/帮助吗?

提前致谢

【问题讨论】:

    标签: python matplotlib seaborn visualization


    【解决方案1】:

    Seaborn 基于 matplotlib,因此您的大部分代码都是相同的。
    只需import seaborn as sns 并将ax.plot 替换为sns.lineplot

    您可能还想添加 sns.set_theme()(或 0.11.0 之前的 sns.set())以应用 seaborn 默认样式。

    【讨论】:

      猜你喜欢
      • 2018-11-23
      • 2017-11-24
      • 2019-10-21
      • 2019-07-13
      • 2014-07-11
      • 2021-03-14
      • 2021-10-14
      • 2019-04-12
      • 1970-01-01
      相关资源
      最近更新 更多