pandas Untergrundstücke in einer Schleife

Ich habe diesen Code, der meine Diagramme in einer Zeile und in 6 Spalten gut darstellt. Ich habe erfolglos versucht, ihn in einem 2x3- oder 3x2-Format darzustellen. Fehlt etwas in der .plot () -Implementierung von Pandas?

fig, axes = plt.subplots(nrows=1, ncols=6)
spfvL = [6, 11, 22, 33, 44, 55]
for j, i in enumerate(spfvL):
    df['spfv' + str(i)] = pd.rolling_std(df['r VIX'], i)*np.sqrt(252)
    res = smf.ols(formula='spfv'+ str(i)+' ~ Q(\'VIX Index\')', data=df).fit()
    df['pred'+ str(i)] = better_predict(res, df)
    df.loc[:,['pred' + str(i), 'spfv' + str(i)]].plot(ax=axes[j])

edit: um 2x3 zu bekommen habe ich das unten versucht, keine große Veränderung.

axes hat eine (2,3) Form und ich kann den korrekten Parameter nicht in die letzte Zeile ax = axis übergeben. Idealerweise sollte ich so etwas wie ax = axis [x] [y] haben, wobei (x, y) in [(0,0), (0,1), (0,2), (1,0), (1 , 1), (1,2)] haben also die exakte Form von Achsen, aber ich bin nur in der Lage, diese Liste von "Indizes" zu erhalten ...

fig, axes = plt.subplots(nrows=2, ncols=3)
spfvL = [6, 11, 22, 33, 44, 55]
for j, i in enumerate(spfvL):
    df['spfv' + str(i)] = pd.rolling_std(df['r VIX'], i)*np.sqrt(252)
    res = smf.ols(formula='spfv'+ str(i)+' ~ Q(\'VIX Index\')', data=df).fit()
    df['pred'+ str(i)] = better_predict(res, df)
    df.loc[:,['pred' + str(i), 'spfv' + str(i)]].plot(ax=axes[j])

Antworten auf die Frage(4)

Ihre Antwort auf die Frage