The information below may be superfluous if you are trying to understand the error message. Please start off by reading the answer by @Evertplt.subplots()의 축은 "numpy.ndarray"객체이며 "plot"속성이 없습니다.
MatPlotLib를 사용하여 내 데이터에서 다음을 만드는 일반화 가능 스크립트가 필요했습니다.
열당 B 줄거리가되도록 배치 줄거리를 포함하는 창. 및 b의 값을 변경하고 싶습니다.I은 2A 줄거리에 대한 데이터가있는 경우
는, I는 전술 한 "열당 B 줄거리에 따라 배열 줄거리"2 윈도우 각 원한다. I 플롯하고 X 및 Y 데이터 np.arrays 저장 수레하며로 구성된다 다음 :x 및 데이터는 항상 모든 그래프에 대해 동일하고 길이 5.
'x_vector': [0.000, 0.005, 0.010, 0.020, 0.030, 0.040]
모든 그래프의 y 데이터는 11 번째 줄거리 내지 제 플롯 데이터 번째 줄거리의 데이터 인덱스 (6)에 저장되어있는 제 통해 인덱스 0에 저장된다 y_vector에 저장된 12-18, 4 번째 19 -24, 등등.
전체적으로이 데이터 세트의 경우 91 개의 플롯 (즉, 91 * 6 = 546 값이 y_vector에 저장 됨)이 있습니다.
시도 :
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
나는 다음과 같은 오류 얻을 : 당신은 단순히 ax
를 인쇄하여 프로그램을 디버깅 할 경우
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'
numpy 가져 오기는 중요하지 않습니다. matplotlib (pyplot)은 matplotlib의 주요 종속성이 있으므로 이미 배후에서 작업합니다. – Evert