# Hline and PlotlyJS

**URL:** <https://discourse.julialang.org/t/hline-and-plotlyjs/97677>\
**Category:** General Usage\
**Tags:** plotlyjs\
**Created:** [April 19, 2023, 8:29pm UTC](https://discourse.julialang.org/t/hline-and-plotlyjs/97677 "2023-04-19T20:29:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [April 19, 2023, 8:29pm UTC](https://discourse.julialang.org/t/hline-and-plotlyjs/97677/1 "2023-04-19T20:29:34Z")

</div>

Today it gave me a bit of a headache to figure out how to use the function `hline()` inside a `PlotlyJS`-figure.  
By text string search inside the `PlotlyJS`-package I was able to put a minimal example together, I hope it helps others to get started.  
Maybe someone knows a good tutorial for `PlotlyJS` that describe such things as `xref="paper"` in combination with `shapes`?  
Here my example:

```julia
function myplot()
    trace_ = scatter(;x = [1,2,3,4,5], y = [-2,-1,0,1,2])
    plt_layout = PlotlyJS.Layout(;
        shapes = PlotlyJS.hline([0], 0, [0.0, 1.0]; xref="paper", line_color="green", line_dash="dash", ),
    )
    return PlotlyJS.Plot(trace_, plt_layout)
end

hdl_ = myplot()

```

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [April 19, 2023, 9:29pm UTC](https://discourse.julialang.org/t/hline-and-plotlyjs/97677/2 "2023-04-19T21:29:21Z")

</div>

It’s easier to use `add_hline!, add_vline!` :

```julia
function myplot()
    fig = Plot(scatter(;x = [1,2,3,4,5], y = [-2,-1,0,1,2]), 
               Layout(width=600, height=400))
    add_hline!(fig, 0.0; line_color="green", line_dash="dash")
    add_vline!(fig, 3.5; line_color="red")
    add_vrect!(fig, 1.5, 2; line_width=0, fillcolor="red", opacity=0.2)
    fig
end
hdl_ = myplot()

```
