0

i'm trying to plot two QQ plots side by side. I looked at enter link description here but not sure how to assign them still. A Q–Q plot quantile-quantile plot) is a probability plot to comparing two probability distributions by plotting their quantiles against each other.

Here is my reproducible example:

import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats

df = sns.load_dataset('tips')

x, y = df['total_bill'], df['tip']
fig, ax = plt.subplots()
stats.probplot(x, dist='norm', plot=ax)
stats.probplot(y, dist='norm', plot=ax)
plt.title ('QQ plot x and y')
plt.savefig ( 'qq.png', dpi=300)
gregV
  • 987
  • 9
  • 28

1 Answers1

1

You can define two subplots intially and then assign the stats.probplot() to each of the axes. Updated code below. Hope this is what you are looking for.

import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats

df = sns.load_dataset('tips')

x, y = df['total_bill'], df['tip']
## Indicate number of rows and columns
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(10,5))

## Create first subplot and assign it to the first plot ax[0]
stats.probplot(x, dist='norm', plot=ax[0])
## Optionally, remove the default title text
ax[0].set_title('')

## Repeat for second plot at ax[1]
stats.probplot(y, dist='norm', plot=ax[1])
ax[1].set_title('')

## Add single title with name you want
fig.suptitle('QQ plot x and y', fontsize=15)

enter image description here

Redox
  • 9,321
  • 5
  • 9
  • 26