I have a function which is of the form :
def f(x, y):
total = 0
u = np.zeros(10)
for i in range(0,10):
u[i] = x * i + y* i
if u[i] < 10:
print('do something')
total = total + u[i]
return total
this function when i try with a given x and y values works well.
f(3,4)
Out[49]: 63.0
I want to create a 3d contour plot using matplotlib. Tried with
x = np.linspace(-6, 6, 30)
y = np.linspace(-6, 6, 30)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.contour3D(X, Y, Z, 50, cmap='binary')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z');
I had to create a mesh grid for 3d plot. I get an error when I try with this because of the loop in my function. I get an error
ValueError: setting an array element with a sequence.
How to plot 3d graphs if my function has a loop?