julialineplots.jl

Line plot in Julia shows a weird line... is this a bug?


Plot with a strange orange diagonal

I am trying to plot two series (each has 2,000 points) using Plots.plot function in Julia 1.7.3.

When drawing the line plot, Julia displays a weird line that goes from an end of the line to the other across the plane as above. There is a strange orange diagonal, and there's no data point on that line. Does anyone know if this is a bug, or is there any error with my code?

Em_mu = [a_grid.+Es[1] res.mu[:,1]]
Unem_mu = [a_grid.+Es[2] res.mu[:,2]]
Em_dat = DataFrame(wealth = Em_mu[:,1], density1 = Em_mu[:,2])
Unem_dat = DataFrame(wealth = Unem_mu[:,1], density2 = Unem_mu[:,2])
wealth_mat = outerjoin(Em_dat, Unem_dat, on=:wealth)
replace!(wealth_mat.density1, missing => 0)
replace!(wealth_mat.density2, missing => 0)
disallowmissing!(wealth_mat)

wealth_mat = Matrix(wealth_mat)

Plots.plot(wealth_mat[:,1], wealth_mat[:,2:3], title = "Distribution")

Solution

  • It looks like your second series is not sorted by its x values. The line plot connects data points with a line so if it's not sorted you get weird lines like that.