Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple graphs on the same plot in seaborn

Tags:

python

seaborn

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

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 ?

like image 472
ticster Avatar asked Feb 09 '16 22:02

ticster


People also ask

How do you make multiple subplots in Seaborn?

You can use the following basic syntax to create subplots in the seaborn data visualization library in Python: #define dimensions of subplots (rows, columns) fig, axes = plt. subplots(2, 2) #create chart in each subplot sns. boxplot(data=df, x='team', y='points', ax=axes[0,0]) sns.

How do you plot two Seaborn plots side by side?

How to plot two Seaborn lmplots side-by-side (Matplotlib)? To create two graphs, we can use nrows=1, ncols=2 with figure size (7, 7). Create a data frame with keys, col1 and col2, using Pandas. Use countplot() to show the counts of observations in each categorical bin using bars.

How do you plot multiple columns in Seaborn?

We can make multiple columns of the barplot by using the seaborn function group bar. The groupby() method in Pandas is used to divide data into groups depending on specified criteria. In the following example script, we have included the matplotlib library and seaborn module for plotting multiple columns using barplot.


1 Answers

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:

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

like image 145
mwaskom Avatar answered Oct 18 '22 00:10

mwaskom