# Plots: string interpolation in labels?

**URL:** <https://discourse.julialang.org/t/plots-string-interpolation-in-labels/10799>\
**Category:** Visualization\
**Tags:** plots, string-interpolation, latexstrings\
**Created:** [May 9, 2018, 3:25pm UTC](https://discourse.julialang.org/t/plots-string-interpolation-in-labels/10799 "2018-05-09T15:25:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [May 9, 2018, 3:25pm UTC](https://discourse.julialang.org/t/plots-string-interpolation-in-labels/10799/1 "2018-05-09T15:25:24Z")

</div>

I’m solving a differential equation several times where I vary a parameter, say `Kp = linspace(1,5,5)`. The result is a vector of vectors (time series), say `vec` is a vector (1D array) of vectors (time series). I then want to plot these plots in the same plot window. If `t` is the time vector, I then want to plot:

```julia
plot(t,vec)

```

However, I’d also like to insert the values of `K` as labels in the plots. In essence:

```julia
plot(t,vec,label=["Kp = $(Kp[1])" "Kp = $(Kp[2])" ....]

```

where `$` is supposed to indicate string interpolation.

Problem 1: will this work? (I haven’t been able to make it work yet…)  
Problem 2: will it work with the LaTeXString package? I like to use LaTeX syntax, i.e.:

```julia
L"$K_p = $ $(Kp[1])"

```

where the first pair of symbols `$` bracket the LaTeX math expression, while the third time symbol `$` appears, it is meant as string interpolation…

Problem 3: is it even possible to use string interpolation _within_ the LaTeX `$` brackets??

> 

Sorry if the explanation is convoluted.

---

<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:** [May 9, 2018, 10:11pm UTC](https://discourse.julialang.org/t/plots-string-interpolation-in-labels/10799/2 "2018-05-09T22:11:38Z")

</div>

> Problem 1: will this work?

Yes, you can interpolate in labels. Labels are just ordinary strings and you can construct them using any valid Julia code.

Your example code has spaces rather than commas separating list items, which is maybe why it wasn’t working for you?

> [@BLI](#):
>
> will it work with the LaTeXString package? I like to use LaTeX syntax, i.e.:

It won’t work with `L"..."` strings because those treat `$` as literal dollar signs, not as interpolation. But you can make an LaTeX equation with an ordinary string as long as you are willing to put `\` before dollar signs and backslashes, e.g. `"\$K_p = $(Kp[1])\$"`.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [May 10, 2018, 4:30pm UTC](https://discourse.julialang.org/t/plots-string-interpolation-in-labels/10799/3 "2018-05-10T16:30:34Z")

</div>

Thanks. I guess the reason why I didn’t use commas between label elements is that I assumed it is the same rules for these as for, e.g., colors, etc. For colors, I need to do:

```julia
plot(x,[y1,y2], lc = [:blue :red])

```

so I assumed the same was true for labels…

---

<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:** [January 18, 2022, 3:22pm UTC](https://discourse.julialang.org/t/plots-string-interpolation-in-labels/10799/4 "2022-01-18T15:22:35Z")

</div>

> [@stevengj](#):
>
> It won’t work with `L"..."` strings because those treat `$` as literal dollar signs, not as interpolation. But you can make an LaTeX equation with an ordinary string as long as you are willing to put `\` before dollar signs and backslashes, e.g. `"\$K_p = $(Kp[1])\$"` .

Update: for some time now, LaTeXStrings has supported Julia interpolation with `%$`, e.g. `L"K_p = %$(Kp[1])"`
