# Plotting 2\*N array giving a name to each point

**URL:** https://discourse.julialang.org/t/plotting-2-n-array-giving-a-name-to-each-point/81774
**Category:** New to Julia
**Tags:** question, plots
**Created:** [May 27, 2022, 9:57am UTC](https://discourse.julialang.org/t/plotting-2-n-array-giving-a-name-to-each-point/81774 "2022-05-27T09:57:13Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Zerosum](https://avatars.discourse-cdn.com/v4/letter/z/b2d939/32.png) [@Zerosum](https://discourse.julialang.org/u/Zerosum)
#### Post date: [May 27, 2022, 9:57am UTC](https://discourse.julialang.org/t/plotting-2-n-array-giving-a-name-to-each-point/81774/1 "2022-05-27T09:57:13Z")

</div>

I think this is an extremely simple question, but I just can’t really understand how the plot function reads my inputs.

For instance, I want to plot two points with scatter: (1,2) and (2,3) in a two-dimension vector space.

Each point is an outcome of my function. If I put 0.2 to the function, (1,2) comes out.

For each point, I want to give a label. For instance, for (1,2), the label is “0.2”.

2-element Vector{Any}:  
(1, 2)  
(2, 3)

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [May 27, 2022, 12:12pm UTC](https://discourse.julialang.org/t/plotting-2-n-array-giving-a-name-to-each-point/81774/2 "2022-05-27T12:12:30Z")

</div>

Which plotting library are you using? For the most part, points to plot are provided as a vector of x coordinates and a vector of y coordinates. In your case you could do this as:

```julia
plot(first.(points), last.(points)

```

where I’m assuming that `points` is the 2-element vector of length-2 tuples you posted above.

Annotations vary by plotting package, so again if you want specific advise you’ll need to tell us which package you’re using.

---

<div class="post-metadata">

### Author: ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)
#### Post date: [May 27, 2022, 12:27pm UTC](https://discourse.julialang.org/t/plotting-2-n-array-giving-a-name-to-each-point/81774/3 "2022-05-27T12:27:09Z")

</div>

`Plots.jl` is clever enough to recognize a vector of 2-tuples as coordinates. Doing `scatter([(1,2),(3,4)])` produces

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/2/c262562800521867952b4d5ae999f37b4e6e8e74.jpeg)

---

<div class="post-metadata">

### Author: ![Zerosum](https://avatars.discourse-cdn.com/v4/letter/z/b2d939/32.png) [@Zerosum](https://discourse.julialang.org/u/Zerosum)
#### Post date: [May 27, 2022, 12:39pm UTC](https://discourse.julialang.org/t/plotting-2-n-array-giving-a-name-to-each-point/81774/4 "2022-05-27T12:39:33Z")

</div>

Thank you very much for the replies.  
I’m using Plots.ji.

I’ve tried with the above one, but it returns the following.  
This is only half of what I want.

Somehow, the scatter function is perceiving my input only as y1, but what I’m putting in is a 19-element vector of which each row is a two-dimension array. I want to label from y1 to y19, for instance.

 ![Screen Shot 2022-05-27 at 2.40.00 PM](https://global.discourse-cdn.com/julialang/original/3X/f/f/ff0f4f3dfd37915f1cca81019c90e101bee0c400.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: [May 27, 2022, 1:17pm UTC](https://discourse.julialang.org/t/plotting-2-n-array-giving-a-name-to-each-point/81774/5 "2022-05-27T13:17:04Z")

</div>

One way:

```julia
using Plots, Printf
x = LinRange(0,1,19)
v = [(rand(0:9),rand(0:9)) for _ in 1:19]

plot(legend=:outerright)
for (i,t) in pairs(v)
    scatter!(t, label=@sprintf("%.2f",x[i]))
end
Plots.current()

```

---

<div class="post-metadata">

### Author: ![Zerosum](https://avatars.discourse-cdn.com/v4/letter/z/b2d939/32.png) [@Zerosum](https://discourse.julialang.org/u/Zerosum)
#### Post date: [May 27, 2022, 1:39pm UTC](https://discourse.julialang.org/t/plotting-2-n-array-giving-a-name-to-each-point/81774/6 "2022-05-27T13:39:04Z")

</div>

I didn’t expect that the problem will be this complicated.  
In the end, I could manage to get the following plot. I really appreciate your suggestion.

If I may ask one more thing, I was wondering if there is any way that I can put each label right above each point in the diagram.

Thank you very much again

 ![Screen Shot 2022-05-27 at 3.33.39 PM](https://global.discourse-cdn.com/julialang/original/3X/f/3/f3323afa1fa8eca99c37fd55dc4b4e9910a8e43a.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: [May 27, 2022, 1:47pm UTC](https://discourse.julialang.org/t/plotting-2-n-array-giving-a-name-to-each-point/81774/7 "2022-05-27T13:47:44Z")

</div>

> [@Zerosum](#):
>
> if there is any way that I can put each label right above each point in the diagram

Yes, [see one example here](https://discourse.julialang.org/t/mark-each-scatter-point-uniquely/58803/4).

---

<div class="post-metadata">

### Author: ![Zerosum](https://avatars.discourse-cdn.com/v4/letter/z/b2d939/32.png) [@Zerosum](https://discourse.julialang.org/u/Zerosum)
#### Post date: [May 27, 2022, 2:12pm UTC](https://discourse.julialang.org/t/plotting-2-n-array-giving-a-name-to-each-point/81774/8 "2022-05-27T14:12:41Z")

</div>

Thank you very much!
