-2

c = np.cos(20)**2

d = np.sin(20)**2

x = np.linspace(-np.pi,np.pi)

y = np.linspace(-np.pi, np.pi)

z = np.abs(np.cos(20 * (c + d)))

x,y = np.meshgrid(x,y)

plt.imshow(z)

So this is the code so far. It's supposed to produce a plasma effect

enter image description here This was the result, which is not what I'm expecting.

9769953
  • 10,344
  • 3
  • 26
  • 37
  • `z` is zero dimensional (i.e., a scalar), not two dimensional. It appears you expect a bit too much magic, by having x and y, but z unrelated to x and y. See Arkadipta's answer for a good example, or search around on the matplotlib gallery / example pages. – 9769953 Oct 27 '22 at 14:24

1 Answers1

1

Not sure if this is what you were trying, but here is an example of code that works without the error. Maybe you can tweak it to your liking:

from matplotlib import pyplot as plt
def z_function(x,y):
    c = np.cos(x)**2
    d = np.sin(y)**2
    z = np.abs(np.cos(20 * (c + d)))
    return z
x = np.linspace(-np.pi,np.pi)
y = np.linspace(-np.pi, np.pi)


xx,yy = np.meshgrid(x,y)
Z = z_function(xx,yy)
plt.imshow(Z)

Image