Plot a diagonal 1:1 line in a marginalkde plot

Hi, I am trying to add a diagonal 1:1 line to a marginalkde plot.

I found that there is Plots.abline! which draws a straight line in the form of ax+b respecting axis limits of the plot. However, my attempt below draws the 1:1 line on the top marginal density plot instead of drawing it in the center plot (that shows the cumulative probability mass).

using StatsPlots
using Plots
x = randn(1024)
y = randn(1024)
marginalkde(x, x+y)
Plots.abline!(1, 0, line=:dash)

Please, do you have any tips how to fix this?

Many thanks in advance.

You can do:

p = marginalkde(x, x+y)
plot!(p.spmap[:contour], x -> x, c=:red)

1 Like
Plots.abline!(1, 0, line=:dash, subplot = 3)

should work too


Yes it does and it is a much simpler access to subplots. Thanks.
(NB: should be subplot=2)