# I am trying to make conformal plots of complex functions using Python, yet I keep getting plots for the inverse function.

I am trying to make a conformal plot of complex functions using contours in python using Matplotlib and NumPy. The thing is, whenever I run the code I get a plot for the inverse function.

For example, say I want to plot $$f(z) = z^{2}$$ : I would use this code:

import numpy as np

def f(z):
return z**2  #definig function as x^2

x = np.linspace(-4,4,100) #real part of input
y = np.linspace(-4,4,100) #imaginary part of input

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

w = f(X + 1j*Y) #Plugging the real and imaginary parts into the function

plt.contour(X,Y, np.real(w)) #plots contour with the real part of the output
plt.contour(X,Y, np.imag(w)) #plots contour with the real part of the output

plt.show()


This gives me this picture:

The problem is that is the plot of the inverse function $$f^{-1}(z) = \sqrt{z}$$.

The picture I should have gotten should look like this:

I got that picture by changing $$f(z)$$ from $$z^2$$ to $$\sqrt{z}$$. I have had this problem with every function I have tried including $$sin(z), \ exp(z), \ x^3$$ and various other polynomials. Aside from this, I have genuinely no idea what to do or where to go from here. nor do I know what the problem actually is.

Note: I have not take complex analysis before so I dont have much knowledge about the subject so sorry if I misuse any terminology. The main reason I am doing any of this is because I think the plots look pretty. My main reference for how the plots should look is this geogebra project I made a while ago: https://www.geogebra.org/m/phmtsgrf

Why do you think the first plot is plot for the inverse function? It looks like the correct plot for $$f(z)$$ to me.

For example, $$Re f(z) = Re (x+iy)^2 = x^2 - y^2$$ so the contours should be curves of the form $$x^2 - y^2 = c$$. That's exactly what the first plot looks like to me.

• Hmm, that seems to be right. The reason I think the plots I got is inverted is because 1) I made a geogebra plot that Im very sure is reliable and it tells me thatt I got the wrong plot and 2) whenever I google images of plots for z^2 i get the same plot I get when I plug in sqrt(z) and vice versa. However what you are saying seems to be about right. so either I am really thick or using contours for this kind of plot is also not a very good idea. Aug 18, 2021 at 12:40

On your GeoGebra plot, the red and blue lines are the images of the grid (lines parallel to the axes) under the mapping.

Here, your contours are contours of constant value. That is why there is a difference in the resulting plots.

• I mean, I was sure that the plots are the same because when I plot $f(z) = z$ I get the same grid as I have in my geogebra plot, which should mean they are taking the same input. I also get the same plot for $f(z) = \frac{1}{z}$ which is the only function that I tried where I get the same result and its also the only fuction I tried where it is its own inverse (aside from $f(z) = z$) Aug 18, 2021 at 12:34
• Interesting! In any case, you can plot a few points and see that the code you wrote here is working properly. You can also trace out a blue line on GeoGebra, and see this maps exactly to one of the blue lines in the image.
– mjw
Aug 18, 2021 at 12:37