微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

手动将误差线添加到 seaborn 线标记图中

如何解决手动将误差线添加到 seaborn 线标记图中

我有 xmeanstd 列。我想用使用 seaborn 的标记绘制线条:

import seaborn as sns
import matplotlib.pyplot as plt

x = [0,1,2]
mean = [2,3]
std = [0.1,0.4,0.2]

sns.lineplot(x=x,y=mean,marker='o')

如何将 std 添加为误差条?

解决方法

来自 seaborn 文档,

markers : boolean,list,or dictionary,optional
    Object determining how to draw the markers for different levels of the
    ``style`` variable. Setting to ``True`` will use default markers,or
    you can pass a list of markers or a dictionary mapping levels of the
    ``style`` variable to markers. Setting to ``False`` will draw
    marker-less lines.  Markers are specified as in matplotlib.

markersstylelineplot 选项一起使用。在您的情况下,使用 marker,它传递给 plt.plot,而不是 markers

sns.lineplot(x=x,y=mean,marker='o')

输出:

enter image description here

,

我找到了一个适合我的答案:

df = pd.DataFrame({'x':x,'y':mean,'std':std})

g = sns.FacetGrid(df,size=5)
g.map(plt.errorbar,"x","y","std",marker="o")

plot

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。