【问题标题】:Coloring the area under the graph in lineplot of seaborn? [duplicate]在seaborn的线图中为图形下的区域着色? [复制]
【发布时间】:2021-12-02 16:24:59
【问题描述】:

我使用 seaborn 的线图从数据中绘制,其代码如下所示:

sns.lineplot( x=df["#Energy"], y=df["py"]+df["px"]+df["pz"])

我得到的情节是

现在我想把它下面的区域涂成不透明的蓝色,我该怎么做 我在 seaborn lineplot 文档中没有找到任何相关的内容 感谢所有帮助的努力

【问题讨论】:

    标签: python matplotlib seaborn line-plot


    【解决方案1】:

    Seaborn 似乎没有这样的功能。不过,你可以使用plt.fill_between

    import pandas as pd
    import seaborn as sns
    import matplotlib.pyplot as plt
    
    df = pd.DataFrame([[0, 0], [1, 1], [2, 0]], columns=['x', 'y'])
    
    fig, ax = plt.subplots()
    sns.lineplot(x=df['x'], y=df['y'], ax=ax)
    ax.fill_between(df['x'], df['y'], alpha=0.2)
    plt.show()
    

    它产生以下内容:

    【讨论】:

      猜你喜欢
      • 2020-08-21
      • 2021-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 2019-04-14
      • 2021-12-28
      相关资源
      最近更新 更多