Achsen von plt.Nebenhandlungen() ist eine “numpy.ndarray" - Objekt hat kein Attribut "plot"

Die folgenden Informationen können überflüssig werden, wenn Sie versuchen zu verstehen, die Fehlermeldung. Bitte beginnen Sie durch das Lesen die Antwort
durch @user707650.

Mit MatPlotLib, ich wollte eine verallgemeinerbare Skript erstellt die folgenden von meinen Daten.

Sich ein Fenster mit eine Nebenhandlungen so angeordnet, dass es b subplots pro Spalte. Ich möchte in der Lage sein, um die Werte zu ändern von eine und b.

Wenn ich Daten für 2a Nebenhandlungen, ich möchte 2 Fenster, jedes mit der zuvor beschriebenen "eine Nebenhandlungen geordnet nach b subplots pro Spalte".

Den x-und y-Daten bin ich Plotten sind floats gespeichert in np.arrays und sind wie folgt strukturiert:

  • Den x-Daten ist immer das gleiche für alle plots und der Länge 5.
     'x_vector': [0.000, 0.005, 0.010, 0.020, 0.030, 0.040]
  • Die y-Daten aller plots gespeichert sind, in y_vector, wo die Daten für den ersten plot gespeichert Indizes 0 bis 5 ist. Die Daten für das zweite Grundstück gelagert wird, Indizes 6 bis 11. Der Dritte plot bekommt 12-18, die vierte 19-24, und so weiter.

Insgesamt, für dieses dataset, ich habe 91 Parzellen (d.h. 91*6 = 546 gespeicherten Werte in y_vector).

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

Bekomme ich die folgende Fehlermeldung:

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'
Import numpy egal: matplotlib (pyplot) schon funktioniert, dass hinter den kulissen, denn es ist eine große Abhängigkeit von matplotlib.

InformationsquelleAutor Lucubrator | 2016-06-22

Schreibe einen Kommentar