Ich habe folgendes:Wie funktioniert die Indizierung von Nebenhandlungen arbeiten
import matplotlib.pyplot as plt
fig = plt.figure()
for i in range(10):
ax = fig.add_subplot(551 + i)
ax.plot([1,2,3,4,5], [10,5,10,5,10], 'r-')
Ich habe mir vorgestellt, dass die 55
bedeutet, dass es ein Gitter schafft, die breit 5 Nebenhandlungen und 5 Nebenhandlungen tief - so kann für 25 sorgen Nebenhandlungen?
Die for-Schleife wird durchlaufen nur 10-mal - so dachte ich (offensichtlich zu Unrecht), dass 25 mögliche Plots diese Iterationen ok empfangen würde, aber ich folgendes:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-118-5775a5ea6c46> in <module>()
10
11 for i in range(10):
---> 12 ax = fig.add_subplot(551 + i)
13 ax.plot([1,2,3,4,5], [10,5,10,5,10], 'r-')
14
/home/blah/anaconda/lib/python2.7/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)
/home/blah/anaconda/lib/python2.7/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 <= 30, not 0
stimme ich dies in der Regel der sauberere Weg ist; Dies erzeugt jedoch alle 25 Teilplots im 5x5-Raster, wobei der OP-Code nur die ersten 10 erzeugt. Sie können alle 25 oder nicht wollen; Ihr Code reproduziert nicht genau, was in der Frage enthalten ist. – tom