# Change the label in plot

**URL:** https://discourse.julialang.org/t/change-the-label-in-plot/41808
**Category:** Visualization
**Created:** [June 21, 2020, 10:39am UTC](https://discourse.julialang.org/t/change-the-label-in-plot/41808 "2020-06-21T10:39:56Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![m.lavaiyan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/m.lavaiyan/32/15846_2.png) [@m.lavaiyan](https://discourse.julialang.org/u/m.lavaiyan)
#### Post date: [June 21, 2020, 10:39am UTC](https://discourse.julialang.org/t/change-the-label-in-plot/41808/1 "2020-06-21T10:39:56Z")

</div>

Hello,  
I am looking for an efficient way to change the label from  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/7/771b5bbd1edd4d8753af88cb11475a11d96bcab4.png)  
to something like

> operation1  
> operation2  
> operation3  
> …

but not with the manual labeling as bellow. Because for a more number of operations it seems not very efficient!

```julia
using StatsPlots;
plot!(label = ["operation1" "operation2" "operation3" ...])

```

Does anyone have an idea? Thanks.

---

<div class="post-metadata">

### Author: ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)
#### Post date: [June 21, 2020, 11:26am UTC](https://discourse.julialang.org/t/change-the-label-in-plot/41808/2 "2020-06-21T11:26:17Z")

</div>

A comprehension does it:

```julia
label = ["operation$j" for j = 1 : n]

```

---

<div class="post-metadata">

### Author: ![m.lavaiyan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/m.lavaiyan/32/15846_2.png) [@m.lavaiyan](https://discourse.julialang.org/u/m.lavaiyan)
#### Post date: [June 21, 2020, 11:43am UTC](https://discourse.julialang.org/t/change-the-label-in-plot/41808/3 "2020-06-21T11:43:45Z")

</div>

> [@hendri54](#):
>
> `label = ["operation$j" for j = 1 : n]`

thank you, I already tried that but it looks like this:

![image](https://global.discourse-cdn.com/julialang/original/3X/1/b/1b4309b34571d01a5a969c0288532a6da53ec0b7.png)

what am I doing wrong?

---

<div class="post-metadata">

### Author: ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)
#### Post date: [June 21, 2020, 11:57am UTC](https://discourse.julialang.org/t/change-the-label-in-plot/41808/4 "2020-06-21T11:57:26Z")

</div>

Apologies - I forgot that legends use 1xn arrays rather than nx1 vectors. This always trips me up. There is probably a nice one-liner that uses a comprehension to make a 1xn Matrix, but I don’t know the way. But a loop is easy.

---

<div class="post-metadata">

### Author: ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)
#### Post date: [June 21, 2020, 11:59am UTC](https://discourse.julialang.org/t/change-the-label-in-plot/41808/5 "2020-06-21T11:59:52Z")

</div>

What I do in practice is have a little function that makes sure a legend is a Matrix. It passes 1xn matrices through without change, but makes vectors into matrices. So I just call `label = make_legend(lbls)` each time and don’t have to worry about whether I had a vector or matrix of labels.

---

<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: [June 21, 2020, 12:20pm UTC](https://discourse.julialang.org/t/change-the-label-in-plot/41808/6 "2020-06-21T12:20:39Z")

</div>

```julia
label = ["operation$j" for j = (1:8)']

```

You need an 1xn matrix

---

<div class="post-metadata">

### Author: ![m.lavaiyan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/m.lavaiyan/32/15846_2.png) [@m.lavaiyan](https://discourse.julialang.org/u/m.lavaiyan)
#### Post date: [June 21, 2020, 12:30pm UTC](https://discourse.julialang.org/t/change-the-label-in-plot/41808/7 "2020-06-21T12:30:37Z")

</div>

Perfect! 👍  
It works exactly the way I want, thank you.

![image](https://global.discourse-cdn.com/julialang/original/3X/9/8/983840885e37048ac23ecacbf46642c7711f00b6.png)
