2

I want to generate a list as below for the legend of my plot,

{D=0, D=0.5, D=1, ...}

using the code

Table["D="  defocus, {defocus, Range[0, 3, 0.5]}]

However, it returns me the following,

{0., 0.5 "D=", 1. "D=", 1.5 "D=", 2. "D=", 2.5 "D=", 3. "D="}

How could I fix this problem? Thank you very much in advance.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Bemtevi77
  • 575
  • 2
  • 7

1 Answers1

5

Use Row to build the legend text.

funcs = Table[With[{k = k}, k # &], {k, 0, 3, 1/2}];
legends = Table[Row[{"D = ", N @ k}], {k, 0, 3, 1/2}];
Plot[Evaluate @ Through[funcs[x]], {x, 0, 5}, PlotLegends -> legends]

plot

m_goldberg
  • 107,779
  • 16
  • 103
  • 257