Reputation: 31
I am trying to plot a point in the complex number plane like that:
from matplotlib.pyplot import*
i = complex(3,1)*2
plot(i,'b.')
show()`
However the resulting plot displays the point z=3+0i
. How can I make it take the imaginary component into account?
Upvotes: 3
Views: 4417
Reputation: 4718
You need to access the real and imaginary parts of your object i
:
plot(i.real,i.imag,'b.')
Edit:
To adress the question you are asking in the comments, you just supply the list of real parts and imaginary parts independently, and you also have to remove the "." from the "b." part, e.g.
# a and b are instances of complex
plt.plot([a.real, b.real], [a.imag, b.imag],"b")
Note that you can find this information using the help()
function on those functions.
Upvotes: 2
Reputation: 281
Casting complex values to real discards the imaginary part.
Please try this
%matplotlib inline
import matplotlib.pyplot as plt
i = complex(3,1)*2
plt.plot(i.real, i.imag,'b.')
plt.show()
Upvotes: 3