ValueError: num muss 1 <= num <= 2, nicht 3
Habe ich Folgendes dataframe
dass ich generiert mit pivot_table
:
und ich bin mit dem folgenden code zu boxplot
mehrere Spalten:
fig = plt.figure()
for i in range(0,25):
ax = plt.subplot(1,2,i+1)
toPlot1.boxplot(column='Score',by=toPlot1.columns[i+1],ax=ax)
fig.suptitle('test title', fontsize=20)
plt.show()
Ich hatte erwartet, eine Ausgabe wie die folgende:
Aber dieser code gibt mir die folgende Fehlermeldung:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-275-9c68ce91596f> in <module>()
1 fig = plt.figure()
2 for i in range(0,25):
----> 3 ax = plt.subplot(1,2,i+1)
4 toPlot1.boxplot(column='Score',by=toPlot1.columns[i+1],ax=ax)
5 fig.suptitle('test title', fontsize=20)
E:\Anaconda2\lib\site-packages\matplotlib\pyplot.pyc in subplot(*args, **kwargs)
1020
1021 fig = gcf()
-> 1022 a = fig.add_subplot(*args, **kwargs)
1023 bbox = a.bbox
1024 byebye = []
E:\Anaconda2\lib\site-packages\matplotlib\figure.pyc in add_subplot(self, *args, **kwargs)
1003 self._axstack.remove(ax)
1004
-> 1005 a = subplot_class_factory(projection_class)(self, *args, **kwargs)
1006
1007 self._axstack.add(key, a)
E:\Anaconda2\lib\site-packages\matplotlib\axes\_subplots.pyc in __init__(self, fig, *args, **kwargs)
62 raise ValueError(
63 "num must be 1 <= num <= {maxn}, not {num}".format(
---> 64 maxn=rows*cols, num=num))
65 self._subplotspec = GridSpec(rows, cols)[int(num) - 1]
66 # num - 1 for converting from MATLAB to python indexing
ValueError: num must be 1 <= num <= 2, not 3
Ich glaube, dass es ist, weil es nur 2 boxplots auf einem Graphen?
Jede Idee, wie man dieses Problem beheben? Alle Zeiger wäre sehr dankbar.
TIA.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Beachten Sie, dass Sie nur erzeugen zwei subplots:
Das erste argument ist die Anzahl der Parzellen, die in jeder Zeile und die zweite die Anzahl der plots pro Reihe (siehe auch die matplotlib.pyplot.Nebenhandlung Dokumentation). So dass die Gesamtzahl der Parzellen verfügbar in Ihrem Fall ist:
1*2 = 2
. Wenn Sie möchten, erstellen 25 zum Beispiel kann man verwenden:5 Grundstücke pro Zeile und 5 pro Spalte hinzufügen, um eine Gesamtzahl von
5*5 = 25