# Plot with not imaginary part

**URL:** <https://discourse.julialang.org/t/plot-with-not-imaginary-part/3458>\
**Category:** Visualization\
**Created:** [May 1, 2017, 1:10pm UTC](https://discourse.julialang.org/t/plot-with-not-imaginary-part/3458 "2017-05-01T13:10:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tulio\_Valentim](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@Tulio\_Valentim](https://discourse.julialang.org/u/Tulio_Valentim)\
**Post date:** [May 1, 2017, 1:10pm UTC](https://discourse.julialang.org/t/plot-with-not-imaginary-part/3458/1 "2017-05-01T13:10:47Z")

</div>

Hi, I need to plot a function/array that have complex number. This complex number are giving bad results to my graphic, as you can see in the image a line keep going in the corner of the Ellipsoid, this line is not welcome.

In order to fix it a need to filter the array V1a and V1b, excluding all elements that have imaginary part. I try to use V = real(V1a), but it do not work beacause it keep the element and I do not want to plot any element that used to have imaginary part.

Some have any idea how to help me?  
image:

 ![](https://global.discourse-cdn.com/julialang/original/3X/e/4/e44df3d77848107d74b88c0b3a19e270ac61bece.png)

code:  
using PyPlot  
c = [“red”, “green”, “blue”, “black”, “gray”,“violet”, “orange”,“purple”,“yellow”, “Grey”,“Aqua”,“Black”,“BlueViolet”,“Brown”,“Coral”,“Cyan”,“Gold”,“Indigo”,“Lime”,“Magenta”,“Maroon”];  
(n,)=size(c)

θ1 = linspace(-70,20,1000);

αt = 70\*(pi/180) # 70 graus height=“453”\>(θ1\*(pi/180)+ αt))+sqrt(((cos(θ1\*(pi/180) + αt)).^(2.0))-(4.0_cos(αt)Pd1Zt)+0im))/(2.0_cos(αt))  
V1b = ((+cos(θ1\*(pi/180) + αt))-sqrt(((cos(θ1\*(pi/180) + αt)).^(2.0))-(4.0_cos(αt)Pd1Zt)+0im))/(2.0_cos(αt))

plot(θ1, V1a, linewidth=2.0,color=c[2],label = “Pd1 = " \*string(trunc(Pd1,2)), linestyle=”-“)  
plot(θ1, V1b, linewidth=2.0,color=c[2], linestyle=”-")

PyPlot.xlabel(“Θ 1 (Grau)”)  
PyPlot.ylabel(“V1 (p.u1))”)  
PyPlot.title(“Pd1 menor que Pdmax”)  
PyPlot.grid(“on”)

# get the current axis argument of the plot

ax = gca()

ax[:legend](loc=“upper right”)

Thanks a lot

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [May 1, 2017, 1:26pm UTC](https://discourse.julialang.org/t/plot-with-not-imaginary-part/3458/2 "2017-05-01T13:26:46Z")

</div>

Replace all values with an imaginary part with NaN?

---

<div class="post-metadata">

**Author:** ![Tulio\_Valentim](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@Tulio\_Valentim](https://discourse.julialang.org/u/Tulio_Valentim)\
**Post date:** [May 1, 2017, 4:35pm UTC](https://discourse.julialang.org/t/plot-with-not-imaginary-part/3458/3 "2017-05-01T16:35:34Z")

</div>

It works! Tks

---

<div class="post-metadata">

**Author:** ![Tulio\_Valentim](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@Tulio\_Valentim](https://discourse.julialang.org/u/Tulio_Valentim)\
**Post date:** [May 1, 2017, 5:27pm UTC](https://discourse.julialang.org/t/plot-with-not-imaginary-part/3458/4 "2017-05-01T17:27:39Z")

</div>

I just use a function as below  
function retiraImaginario(x)  
(n,) = size(x)  
for i = 1:n  
if (imag(x)[i]!=0.0)  
x[i]= NaN  
end  
end  
end
