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!
using StatsPlots;
plot!(label = ["operation1" "operation2" "operation3" ...])
Does anyone have an idea? Thanks.
A comprehension does it:
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?
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.
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.
label = ["operation$j" for j = (1:8)']
You need an 1xn matrix
4 Likes
Perfect! ![:+1: :+1:](https://emoji.discourse-cdn.com/twitter/+1.png?v=12)
It works exactly the way I want, thank you.
![image](https://global.discourse-cdn.com/julialang/original/3X/9/8/983840885e37048ac23ecacbf46642c7711f00b6.png)