0

I am trying to plot the power generated by a wind turbine in function of the number of hours in a day and number of days in a year.

I made this small program :

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

But I am getting this error:

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

1 Answer 1

1

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

X,Y,Z Data values as 2D arrays

In your case d and y are 1D. To create 2D arrays numpy.meshgrid is often useful.

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.