Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python matplotlib Axes3D错误_Python_Matplotlib - Fatal编程技术网

Python matplotlib Axes3D错误

Python matplotlib Axes3D错误,python,matplotlib,Python,Matplotlib,我试图根据一天中的小时数和一年中的天数来绘制风力涡轮机产生的功率 我制作了一个小程序: 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]

我试图根据一天中的小时数和一年中的天数来绘制风力涡轮机产生的功率

我制作了一个小程序:

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()
但我得到了这个错误:

ValueError:形状不匹配:无法将对象广播到单个 形状

警察说

X,Y,Z
数据值作为二维数组

在您的情况下,
d
y
是1D。创建二维数组通常很有用

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()