# Add tag with coordinates to plot in Plots.jl

**URL:** <https://discourse.julialang.org/t/add-tag-with-coordinates-to-plot-in-plots-jl/58972>\
**Category:** General Usage\
**Tags:** question, plots, inspectdr\
**Created:** [April 10, 2021, 9:15am UTC](https://discourse.julialang.org/t/add-tag-with-coordinates-to-plot-in-plots-jl/58972 "2021-04-10T09:15:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![achjaj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/achjaj/32/22358_2.png) [@achjaj](https://discourse.julialang.org/u/achjaj)\
**Post date:** [April 10, 2021, 9:15am UTC](https://discourse.julialang.org/t/add-tag-with-coordinates-to-plot-in-plots-jl/58972/1 "2021-04-10T09:15:40Z")

</div>

I have a plot with intersecting lines:  
 ![plot](https://global.discourse-cdn.com/julialang/original/3X/f/c/fcd936af03e11a368061f11405eb9343e60e3145.png)

And I would like to add a tag or pointer which point to the intersection and display the coordinates of the intersection. Something like this:  
 ![tag example](https://global.discourse-cdn.com/julialang/original/3X/d/0/d0d60e497e40d0fea6647bf384952b71ecf232e8.png)

I know the coordinates of the intersection and I know that the function `annotate!` adds text to the plot. However, I do not know how to add an line or arrow to point to the intersection and how to determine the right position for the text.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [April 10, 2021, 10:07am UTC](https://discourse.julialang.org/t/add-tag-with-coordinates-to-plot-in-plots-jl/58972/2 "2021-04-10T10:07:27Z")

</div>

Here’s the start of a hack if you want one:

```julia
plot([(1, 0), (0, 1)]; arrows=true, texts=["hi",""])

```

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [April 10, 2021, 11:44pm UTC](https://discourse.julialang.org/t/add-tag-with-coordinates-to-plot-in-plots-jl/58972/3 "2021-04-10T23:44:39Z")

</div>

@gustaphe’s suggestion is good. Just remember that the coordinates are data-relative (not plot display-relative). So zooming in will make the marker bigger.

### Alternative using single-point dataset & marker:

You can add the marker as a simple shape that will resize itself when you zoom in. But I don’t see a way to offset the text in a display-relative manner either. Your best bet is probably to specify the alignment of the text as `:bottom, :left`, or something (see below):

```julia-auto
pt = (3,9) #where to place the marker

#Add a single point using marker formatted as desired:
plot!([pt[1]],[pt[2]], markershape=:plus,
	markercolor=:grey, markerstrokecolor=:black, markerstrokewidth=3,
	markersize=10
)

#Annotate with x-value
ptstr = string(pt)
xvalstr = string(pt[1]) #Just x value
annotate!((pt...,text(xvalstr, 14, :bottom, :left, :green)))

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/6/463b1478a048799053384c04701392712ba8645b.png)

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [April 10, 2021, 11:55pm UTC](https://discourse.julialang.org/t/add-tag-with-coordinates-to-plot-in-plots-jl/58972/4 "2021-04-10T23:55:49Z")

</div>

If you don’t need add these markers in an automated fashion, the InspectDR backend allows you to add them using the `r` and `d` keys (keyboard).

- `r`: reference marker: a single point with `(x,y)` coords displayed.
- `d`: The delta marker: couples with the last reference marker to calculate the distance & slope between them (box can be moved with click+drag).

(more info on mouse/key bindings here:)  
 → [InspectDR.jl/doc/input\_bindings.md at master · ma-laforge/InspectDR.jl · GitHub](https://github.com/ma-laforge/InspectDR.jl/blob/master/doc/input_bindings.md)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/5/d52a76e6c9e9c9cfdd634f45de7b8804be3f4b7a.png)

Note:

- The top-left marker is a single marker generated with r while hovering over the plot.
- The 2 markers on the right were created with the `r`-`d` key combination.

### Limitation

I don’t think there is an API yet to generate these markers programmatically, but it probably can be added without requiring a much new code (you can open a PR if this interests you).

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [April 11, 2021, 12:02am UTC](https://discourse.julialang.org/t/add-tag-with-coordinates-to-plot-in-plots-jl/58972/5 "2021-04-11T00:02:18Z")

</div>

And since you are working with frequency plots, you might be interested in knowing that InspectDR allows you to stack multiple y strips that maintains a common frequency window as you zoom in interactively.

This is ideal for Bode plots (see below)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/8/28e74dd270939e0763992a83b64c3c9b1a0a93d2.png)

### Limitation

At the moment, this feature does not work with Plots.jl’s linked axes system (only works with stacked y strips; not plots with linked x axes).
