【问题标题】:Seaborn chart converging on same point not visibleSeaborn 图表收敛于同一点不可见
【发布时间】:2019-02-27 23:05:46
【问题描述】:

我有一个包含两列的数据框 - VOL、INVOL 和特定年份的值是相同的。因此,在 seaborn 中绘图时,当它们收敛时,我无法看到另一列的值。

例如: 我的数据框是

当我使用 seaborn 时,使用下面的代码

f5_test = df5_test.melt('FY', var_name='cols',  value_name='vals')

g = sns.catplot(x="FY", y="vals", hue='cols', data=df5_test, kind='point')

图表未显示相同的 0.06 点。

我尝试使用 pandas 绘图,结果相同。

请告诉我应该怎么做。提前致谢。

【问题讨论】:

    标签: python jupyter-notebook seaborn


    【解决方案1】:

    你的情节看起来合法。两条线完全重叠,因为 2016 年到 2018 年的数据完全相同。我想也许您可以尝试分别绘制两条线,并在其中一条上添加或减去一些小值以稍微移动这条线。例如:

    import pandas as pd
    import seaborn as sns
    import matplotlib.pyplot as plt
    df = pd.DataFrame({'FY': [2012, 2013, 2014, 2015, 2016, 2017, 2018],
                       'VOL_PCT': [0, 0.08, 0.07, 0.06, 0, 0, 0.06],
                       'INVOL_PC': [0, 0, 0, 0, 0, 0, 0.06]})
    # plot
    fig, ax = plt.subplots()
    sns.lineplot(df.FY, df.VOL_PCT)
    sns.lineplot(df.FY+.01, df.INVOL_PC-.001)
    

    此外,鉴于您的数据类型,您还可以考虑使用堆栈图。例如:

    fig, ax = plt.subplots()
    labels = ['VOL_PCT', 'INVOL_PC']
    ax.stackplot(df.FY, df.VOL_PCT, df.INVOL_PC, labels=labels)
    ax.legend(loc='upper left');
    

    参考。 Stackplot

    【讨论】:

    • 非常感谢。这很有帮助。
    猜你喜欢
    • 2019-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-12
    • 1970-01-01
    • 1970-01-01
    • 2019-01-10
    相关资源
    最近更新 更多