# How to create a list of (x, y) labels from an n x 2 matrix of x, y data pairs?

**URL:** <https://discourse.julialang.org/t/how-to-create-a-list-of-x-y-labels-from-an-n-x-2-matrix-of-x-y-data-pairs/96316>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [March 19, 2023, 7:53pm UTC](https://discourse.julialang.org/t/how-to-create-a-list-of-x-y-labels-from-an-n-x-2-matrix-of-x-y-data-pairs/96316 "2023-03-19T19:53:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gary\_Church](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gary_church/32/46086_2.png) [@Gary\_Church](https://discourse.julialang.org/u/Gary_Church)\
**Post date:** [March 19, 2023, 7:53pm UTC](https://discourse.julialang.org/t/how-to-create-a-list-of-x-y-labels-from-an-n-x-2-matrix-of-x-y-data-pairs/96316/1 "2023-03-19T19:53:18Z")

</div>

Greetings,

I’m using Julia 1.8.5, Plots and the plotly backend. I have an n x 2 matrix of x, y data pairs called “data” which I plot using:

```julia
scatter(data[:,1], data[:,2])

```

I want to annotate each of the plotted data points with its coordinates. Evidently, I can do this as:

```julia
annotate!(data[:,1], data[:,2], text.(<array of labels for the points>, :red, :left, 9)

```

But, I need a way of creating the array of string coordinate pairs; e.g. [“(2, 3)”, “(3.4, 6.1)”, …]

If you know a better way of accomplishing the main task (annotating the points of a scatter plot with their coordinates), please let me know about it.

Thanks a lot,  
Gary

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 19, 2023, 8:09pm UTC](https://discourse.julialang.org/t/how-to-create-a-list-of-x-y-labels-from-an-n-x-2-matrix-of-x-y-data-pairs/96316/2 "2023-03-19T20:09:09Z")

</div>

> [@Gary\_Church](#):
>
> But, I need a way of creating the array of string coordinate pairs; e.g. [“(2, 3)”, “(3.4, 6.1)”, …]

For example, `string.('(', data[:,1], ", ", data[:,2], ')')`.

---

<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:** [March 19, 2023, 8:32pm UTC](https://discourse.julialang.org/t/how-to-create-a-list-of-x-y-labels-from-an-n-x-2-matrix-of-x-y-data-pairs/96316/3 "2023-03-19T20:32:17Z")

</div>

This might be more useful:

```julia
string.(Tuple.(eachrow(round.(data, digits=2))))

```

> **MWE**
>
> ```julia
> using Plots; plotly()
> 
> data = rand(10,2)
> labels = string.(Tuple.(eachrow(round.(data, digits=2))))
> Plots.scatter(data[:,1], data[:,2])
> Plots.annotate!(data[:,1], data[:,2], labels, :bottom)
> 
> ```

---

<div class="post-metadata">

**Author:** ![Gary\_Church](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gary_church/32/46086_2.png) [@Gary\_Church](https://discourse.julialang.org/u/Gary_Church)\
**Post date:** [March 21, 2023, 2:18pm UTC](https://discourse.julialang.org/t/how-to-create-a-list-of-x-y-labels-from-an-n-x-2-matrix-of-x-y-data-pairs/96316/4 "2023-03-21T14:18:54Z")

</div>

MWE,

That works brilliantly!

Thanks.
