1

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?

toti08
  • 2,448
  • 5
  • 24
  • 36
user9891079
  • 119
  • 2
  • 10
  • I don't know this statsmodel function, but looking [at their docs](http://www.statsmodels.org/dev/generated/statsmodels.graphics.gofplots.qqplot.html), I assume you have to add `ax = ax[i]` to fill your subplots sequentially. It would be good to have a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Mr. T Oct 15 '18 at 09:38
  • Yes, I already tried that. But if I add: ax = ax[I].sm.qqplot(...) , I get the error: 'AxesSubplot' object has no attribute 'qqplot' – user9891079 Oct 15 '18 at 09:41
  • `ax` is a parameter of the function as you can see in their docs: `sm.qqplot((mEps[i,:]), fit = True, line='q', ax = ax[i])` – Mr. T Oct 15 '18 at 09:44
  • Great, thank you! Sorry I'm still really new to Python – user9891079 Oct 15 '18 at 09:46
  • Next time, please provide an Minimal, Complete, and Verifiable example. I had to guess what sm.qqplot refers to. Imports are part of the code. – Mr. T Oct 15 '18 at 09:47

1 Answers1

0

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