Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain 2 separate plots in seaborn?

I have a big function which output is a dataframe and 2 charts. Something like this:

summary = pd.concat([mean, std], axis=1)
chart1 = sns.tsplot(sample['x'].cumsum())
chart2 = sns.tsplot(summary['mean'])
result = [summary, chart1, chart2]
return result

Everything works fine, except, I only get one chart with the two time series in it. I would like to get two separate charts. How do I do this?

Thanks

like image 317
hernanavella Avatar asked Mar 30 '15 00:03

hernanavella


People also ask

How do you make multiple plots in Seaborn?

In Seaborn, we will plot multiple graphs in a single window in two ways. First with the help of Facetgrid() function and other by implicit with the help of matplotlib. data: Tidy dataframe where each column is a variable and each row is an observation.

How do I show 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.


1 Answers

Feed explicit matplotlib objects to tsplot:

import matplotlib.pyplot as plt
import seaborn as sns

def whatever(mean, std, *args, **kwargs):
    summary = pd.concat([mean, std], axis=1)
    chart1, ax1 = plt.subplots()
    sns.tsplot(sample['x'].cumsum(), ax=ax1)

    chart2, ax2 = plt.subplots()
    sns.tsplot(summary['mean'], ax=ax2)
    result = [summary, chart1, chart2]
    return result
like image 139
Paul H Avatar answered Oct 11 '22 15:10

Paul H