Axes from plt.subplots () ist ein "numpy.ndarray" -Objekt und hat kein Attribut "plot"
Die folgenden Informationen sind möglicherweise überflüssig, wenn Sie versuchen, die Fehlermeldung zu verstehen. Bitte beginnen Sie mit dem Lesen vondie Antwor durch@ user707650.
Mit MatPlotLib wollte ich ein verallgemeinerbares Skript, das aus meinen Daten Folgendes erstellt.
Ein Fenster mita Untergrundstücke so angeordnet, dass esb Unterzeichnungen pro Spalte. Ich möchte die Werte von @ ändern könna undb.
Wenn ich Daten für @ ha 2a subplots, ich möchte 2 fenster mit den zuvor beschriebenen "a Untergrundstücke sortiert nachb Unterzeichnungen pro Spalte ".
Die X- und Y-Daten, die ich zeichne, sind Floats, die in np.arrays gespeichert und wie folgt strukturiert sind:
Die x-Daten sind für alle Diagramme immer gleich und haben die Länge 5.
'x_vector': [0.000, 0.005, 0.010, 0.020, 0.030, 0.040]
Die y-Daten aller Diagramme werden in @ gespeicher y_vector wobei die Daten für den ersten Plot bei den Indizes 0 bis 5 gespeichert sind. Die Daten für den zweiten Plot werden bei den Indizes 6 bis 11 gespeichert. Der dritte Plot erhält 12-18, der vierte 19-24 und so weiter.
nsgesamt habe ich für diesen Datensatz 91 Diagramme (d. H. 91 * 6 = 546 in y_vector gespeicherte Werte
Versuch
import matplotlib.pyplot as plt
# Options:
plots_tot = 14 # Total number of plots. In reality there is going to be 7*13 = 91 plots.
location_of_ydata = 6 # The values for the n:th plot can be found in the y_vector at index 'n*6' through 'n*6 + 6'.
plots_window = 7 # Total number of plots per window.
rows = 2 # Number of rows, i.e. number of subplots per column.
# Calculating number of columns:
prim_cols = plots_window / rows
extra_cols = 0
if plots_window % rows > 0:
extra_cols = 1
cols = prim_cols + extra_cols
print 'cols:', cols
print 'rows:', rows
# Plotting:
n=0
x=0
fig, ax = plt.subplots(rows, cols)
while x <= plots_tot:
ax[x].plot(x_vector, y_vector[n:(n+location_of_ydata)], 'ro')
if x % plots_window == plots_window - 1:
plt.show() # New window for every 7 plots.
n = n+location_of_ydata
x = x+1
Ich erhalte den folgenden Fehler:
cols: 4
rows: 2
Traceback (most recent call last):
File "Script.py", line 222, in <module>
ax[x].plot(x_vector, y_vector[n:(n+location_of_ydata)], 'ro')
AttributeError: 'numpy.ndarray' object has no attribute 'plot'