Why I can't connect 2 complex dots using plot([z1],[z2]...)?

Hi all,

I try this code:

using Plots, LaTeXStrings

z1 = 4+2im
z2 = 4-2im
z3 = z1+z2
z4 = z1-z2

plot([z1], framestyle = :zerolines, label=L"z = 4 + 2i"; st=:scatter, legend=:outerright)
plot!([z2], label=L"z = 4 - 2i"; st=:scatter)
plot!([z3], label=L"z + \bar{z} = \ 2a"; st=:scatter)
plot!([z4], label=L"z - \bar{z} = \ 2ib"; st=:scatter)
    
# vertical green line connecting the dots

plot!([0,4],[4,2], label="", linecolor=:green, linestyle=:dash)
plot!([8,4],[0,2], label="", linecolor=:green, linestyle=:dash)
plot!([8,4],[0,-2], label="", linecolor=:green, linestyle=:dash)
plot!([0,4],[0,2], label="", linecolor=:green, linestyle=:dash)
plot!([0,4],[0,-2], label="", linecolor=:green, linestyle=:dash)

it plots nicely, but I wonder why I can’t use:

plot!([z1],[z2], label="", linecolor=:green, linestyle=:dash)

error:
MethodError: no method matching isless(::Float64, ::ComplexF64)

instead of the old plot a line code…

Maybe you want this notation instead:

scatter([z1, z2])
plot!([z1, z2], label="", linecolor=:green, linestyle=:dash)

(edited: is this what you want?)

1 Like

Yes, basically they plot the same but to write this code:

plot!([z1, z2], label="", linecolor=:green, linestyle=:dash)

is more convenient and efficient. Thanks

You can concatenate the lines using plot!([z4, z3, z1, z2, 0im, z4]) (in the correct order, to have a single plot command build the complete line (or scatter).