问题描述
我正在尝试为某些数据绘制条形样式factorplot",然后绘制一个常规点样式factorplot",以便在其上拟合该数据.所以对于数据图,我可以简单地做:
I'm trying to plot a bar style "factorplot" for some data, then plot a regular point style "factorplot" for my fit of that data on top of it. So for the data plot I can simply do :
sns.factorplot(x='x',y='yData',data=dataFrame,kind='bar')
对于模型图,我可以简单地做:
And for the model plot I can simply do :
sns.factorplot(x='x',y='yModel',data=dataFrame,kind='point')
问题是,如果我这样做:
The problem is that if I then do :
sns.plt.show()
我得到了 2 个不同的数字,而不是一个.有没有什么简单的方法可以告诉 seaborn 将它们绘制在同一张图上?
I get 2 separate figures instead of just one. Is there any simple way to tell seaborn to just plot them on the same graph ?
推荐答案
如评论中所述,这个答案 解释了解释为什么你会看到这种行为的基本架构(两个不同的数字),但可以对你的问题给出更具体的答案:
As mentioned in the comments, this answer explains the basic architecture that accounts for why you see that behavior (two different figures), but it's possible to give a more specific answer to your question:
教程 解释了 factorplot
主要是一个方便的函数,它结合了 FacetGrid
和许多轴级函数,用于绘制共享 API 的分类图.由于您没有使用 factorplot
的分面选项,您需要做的就是将 sns.factorplot(..., kind="bar")
替换为 sns.barplot(...)
和 sns.factorplot(..., kind="point")
和 sns.pointplot(...)
>.
The tutorial explains that factorplot
is mostly a convenience function that combines FacetGrid
with a number of Axes-level functions for drawing categorical plots that share an API. Since you aren't using the faceting options of factorplot
, all you need to do is replace sns.factorplot(..., kind="bar")
with sns.barplot(...)
and sns.factorplot(..., kind="point")
with sns.pointplot(...)
.
这篇关于seaborn 中同一图上的多个图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!