Plot smile face

I tried to plot a smile face with julia, the code I’ve used as follows

function face()
t = range(0, 2pi, 200)
r1=0.2;
r2=0.5;
R=1;
y=[0, 0]' .+ hcat(R*cos.(t),R*sin.(t)) # big circle
y1=[-0.3, 0.3]' .+ hcat(r1*cos.(t),r1*sin.(t))  # left small circle
y2=[0.3, 0.3]' .+ hcat(r1*cos.(t),r1*sin.(t))  # right small circle

t = range(-π+π/5, -π/5, 200)
y3= hcat(r2*cos.(t),r2*sin.(t)) #  parabola
Y=[y;y1;y2;y3]
return plot(Y[:,1],Y[:,2],aspect_ratio=1,lc=:black, linestyle=:dot,lw = 2)
end

However, the result with face() gives

Could anyone show me the issue?

You propbably just want to plot all four series separately, i.e.

julia> p = plot(; aspect_ratio = 1)

julia> for x ∈ [y, y1, y2, y3]
           plot!(p, x[:, 1], x[:, 2], color = "black", ls = :dot, label = "")
       end

julia> current()

image

Thanks for your reply, but why didn’t work with the first code.

The plot just connects all the points in a row, it doesn’t know when a different curve begins or ends.

1 Like

You can introduce breaks along the line using NaNs, so you can also just change the line of code merging segments like this:

Y = [y; NaN NaN; y1; NaN NaN; y2; NaN NaN; y3]
1 Like