Reputation: 111
how do I create one plot with 2 seaborn plots (subplots)
How to merge 2 seaborn plots into 1?
plt.figure(figsize = (12, 6))
ax = sns.scatterplot(x = model1.fittedvalues, y = model1.resid)
plt.grid()
ax.axhline(y=0, color='r', linewidth=4)
ax.set_xlabel("vysvětlovaná proměnná");
ax.set_ylabel("residua");
plt.figure(figsize = (12, 6))
ax = sns.distplot(a = model1.resid, bins = 40, norm_hist=True,)
plt.grid()
ax.set_title("Histogram reziduí", fontsize = 25);
Upvotes: 1
Views: 10142
Reputation: 51
You could better to define subplots:
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
x = np.array([4,3,2,3])
y = np.array([5,1,6,4])
**fig, sub = plt.subplots(2,1)**
plt.figure(figsize = (12, 6))
sns.scatterplot(x, y , **ax=sub[0]**)
ax.axhline(y=0, color='r', linewidth=4)
ax.set_xlabel("vysvětlovaná proměnná")
ax.set_ylabel("residua")
plt.figure(figsize = (12, 6))
sns.distplot(x, bins = 40, norm_hist=True, **ax=sub[1]**)
ax.set_title("Histogram reziduí", fontsize = 25)
Upvotes: 0
Reputation: 40737
You can create your subplots anyway you like (using plt.subplots()
, fig.add_subplot()
, GridSpec
, you name it), then pass a reference to the axes to the seaborn functions using ax=<your axes reference>
fig, (ax1, ax2) = plt.subplots(1,2, figsize = (24, 6))
sns.scatterplot(x = model1.fittedvalues, y = model1.resid, ax=ax1)
ax1.grid()
ax1.axhline(y=0, color='r', linewidth=4)
ax1.set_xlabel("vysvětlovaná proměnná");
ax1.set_ylabel("residua");
sns.distplot(a = model1.resid, bins = 40, norm_hist=True, ax=ax2)
ax2.grid()
ax2.set_title("Histogram reziduí", fontsize = 25);
Upvotes: 6