如何解决手动将误差线添加到 seaborn 线标记图中
我有 x
、mean
和 std
列。我想用使用 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.
markers
与 style
的 lineplot
选项一起使用。在您的情况下,使用 marker
,它传递给 plt.plot
,而不是 markers
:
sns.lineplot(x=x,y=mean,marker='o')
输出:
,我找到了一个适合我的答案:
df = pd.DataFrame({'x':x,'y':mean,'std':std})
g = sns.FacetGrid(df,size=5)
g.map(plt.errorbar,"x","y","std",marker="o")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。