# Plot a diagonal 1:1 line in a marginalkde plot

**URL:** https://discourse.julialang.org/t/plot-a-diagonal-1-1-line-in-a-marginalkde-plot/72036
**Category:** Visualization
**Tags:** plots, statsplots
**Created:** [November 24, 2021, 11:48pm UTC](https://discourse.julialang.org/t/plot-a-diagonal-1-1-line-in-a-marginalkde-plot/72036 "2021-11-24T23:48:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rio](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@rio](https://discourse.julialang.org/u/rio)
#### Post date: [November 24, 2021, 11:48pm UTC](https://discourse.julialang.org/t/plot-a-diagonal-1-1-line-in-a-marginalkde-plot/72036/1 "2021-11-24T23:48:44Z")

</div>

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).

```julia
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.

 ![toy](https://global.discourse-cdn.com/julialang/original/3X/0/7/076abdc8e7a35a382e1abf2f35b0dd510afab9d0.png)

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 25, 2021, 8:05am UTC](https://discourse.julialang.org/t/plot-a-diagonal-1-1-line-in-a-marginalkde-plot/72036/2 "2021-11-25T08:05:22Z")

</div>

You can do:

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

```

 ![StatsPlots_marginalkde_with_line](https://global.discourse-cdn.com/julialang/original/3X/7/3/7378b14e772f942c2cea9d3ec456a310ef5f7f82.png)

---

<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: [November 25, 2021, 9:30am UTC](https://discourse.julialang.org/t/plot-a-diagonal-1-1-line-in-a-marginalkde-plot/72036/3 "2021-11-25T09:30:53Z")

</div>

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

```

should work too

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 25, 2021, 9:34am UTC](https://discourse.julialang.org/t/plot-a-diagonal-1-1-line-in-a-marginalkde-plot/72036/4 "2021-11-25T09:34:24Z")

</div>

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