Multiple qq plots in one figure

1.9k views Asked by At

I have a matrix mEps which is of shape (10, 1042), where 10 is the number of assets, and 1042 is the amount of datapoints. I want to show the Q-Q plot for each asset, so I can plot:

for i in range(iN):
    sm.qqplot((mEps[i,:]), fit = True, line='q')

However, then I get 10 pictures of Q-Q plots. I would like to have them in one figure, so I have the following code:

fig, axes = plt.subplots(nrows=4, ncols=3, figsize=(15,10))
ax= axes.flatten()
for i in range(iN):
   sm.qqplot((mEps[i,:]), fit = True, line='q')

This code creates the figure, but it doesn't fill it with Q-Q plots.. Does anyone know how to do this?

1

There are 1 answers

0
Kolombo2407 On

QQplot documentation https://www.statsmodels.org/dev/generated/statsmodels.graphics.gofplots.qqplot.html states that function takes as argument "ax" the ax in subplots, where you want to place your qqplot

fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(10,4))

qqplot(data_a['metrics'], line='s', ax=ax1)
qqplot(data_b['metrics'], line='s', ax=ax2)
ax1.set_title('Data A')
ax2.set_title('Data B')

plt.show()