2017-11-13 1 views
0

풍력 터빈에 의해 생성 된 전력을 하루의 시간 수와 1 년의 일 수에 따라 플롯하려고합니다. matplotlib Axes3D 오류

나는이 작은 프로그램 제작 :

wPower1 = np.zeros((365, 24)) 
d = np.mat(np.arange(24)) 
print d 
y = np.mat(np.arange(365)) 
for heure in range(24): 
    for jour in range(365): 
     wPower1[jour][heure] = wPower[24 * (jour - 1) + heure] 

print wPower1 
fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
ax.plot_surface(d, y, wPower1, rstride=1, cstride=1, linewidth=0, antialiased=False) 
plt.show() 

을하지만이 오류가 무엇입니까 : dy는 1D입니다 귀하의 경우에는

ValueError: shape mismatch: objects cannot be broadcast to a single shape

답변

1

plot_surface(X, Y, Z, *args, **kwargs) documentation

X,Y,Z Data values as 2D arrays

을 말한다. 2D 배열을 만들려면 numpy.meshgrid이 유용합니다.

import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D 
import numpy as np 

wPower = np.random.rand(365*24) 
wPower1 = wPower.reshape(365, 24) 

d,y = np.meshgrid(np.arange(24),np.arange(365)) 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
ax.plot_surface(d, y, wPower1, rstride=1, cstride=1, linewidth=0, antialiased=False) 
plt.show() 
+0

고맙습니다. D –