Python seaborn 中同一图上的多个图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35303304/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 16:15:32  来源:igfitidea点击:

Multiple graphs on the same plot in seaborn

pythonseaborn

提问by ticster

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 :

我正在尝试为某些数据绘制条形样式“factorplot”,然后绘制一个常规点样式“factorplot”,以便在其上拟合该数据。所以对于数据图,我可以简单地做:

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()

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 ?

我得到 2 个单独的数字,而不是一个。有什么简单的方法可以告诉 seaborn 将它们绘制在同一张图上吗?

采纳答案by mwaskom

As mentioned in the comments, this answerexplains 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:

正如评论中提到的,这个答案解释了解释为什么你会看到这种行为的基本架构(两个不同的数字),但可以对你的问题给出更具体的答案:

The tutorialexplains that factorplotis mostly a convenience function that combines FacetGridwith 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(...).

教程解释说,这factorplot主要是一个方便的函数,它FacetGrid与许多轴级函数相结合,用于绘制共享 API 的分类图。既然你不使用的刻面的选择factorplot,所有你需要做的是替换sns.factorplot(..., kind="bar")sns.barplot(...),并sns.factorplot(..., kind="point")sns.pointplot(...)