Contour plot on Python. TypeError: Input z must be a 2D array

I am trying to contour plot this equation (z) but complier gives me "TypeError: Input z must be a 2D array." error I have tried different methods but it still gives the same error

import matplotlib

import numpy as np

import matplotlib.cm as cm

import matplotlib.pyplot as plt

import math

fig = plt.figure()

ax = fig.add_subplot(111)

a = np.linspace(-6,6,100)

X , Y = np.meshgrid(a,a)

v = 1

a = 1

g1 = 2 * math.pi

g2 = -g1

z =  v * y - v *y *(a**2 / (x**2 + (y- 2*a )**2))  + (g1 / 4 * (math.pi)*(np.log((x**2 +(y-2*a)**2) / a))) -  v * y *(a**2 /(x**2+(y+2*a)**2)) + (g2 / 4*(math.pi)*(np.log((x**2+(y+2*a)**2))) / a)

ax.contourf(X,Y,z)

Upvotes: 1

Views: 326

Answers (1)

Mike Müller
Mike Müller

Reputation: 85432

Renaming all upper case X and Y to lower case x and y creates this picture:

enter image description here

You probably work in a Notebook and use other values for x and y, i.e. scalars.

Upvotes: 1

Related Questions