Take this simple example:
Manipulate[
RegionPlot[
{x^2 + y^2 <= c,
x < 0},
{x, -Pi, Pi},
{y, -Pi, Pi},
PlotLegends -> "Expressions"
],
{{c, 3.}, 0., 10., 0.1}
]
As you can see (unless it's just me of course) the legend text does not display correctly. In particular the value of c
is not substituted correctly when the legend text is evaluated.
Doing some research I found that Manipulate basically works like a DynamicModule, and indeed the following breaks in a very similar way, and I guess for the same reasons:
DynamicModule[{c = 3},
RegionPlot[
{x^2 + y^2 <= c,
x < 0},
{x, -Pi, Pi},
{y, -Pi, Pi},
PlotLegends -> "Expressions"
]
]
while using for example With instead of DynamicModule works correctly.
I could probably fix this by manually inserting the legend with something like
PlotLegends->"x^2+y^2<="<>c
but then I would have to manually tweak the font and all that.
Why does this happen? And what is the correct way to deal with it?
x
is substituted with the value4
and thex<0
part is not shown. $\endgroup$ – glS May 17 '15 at 10:40Manipulate[ RegionPlot[ Evaluate@{x^2 + y^2 <= c, x < 0}, {x, -Pi, Pi}, {y, -Pi, Pi}, PlotLegends -> "Expressions"], {{c, 3.}, 0., 10., 0.1}]
$\endgroup$ – Kuba♦ May 17 '15 at 10:55ClearAll[x]
. It seems that with theEvaluate
the Manipulate doesn't work unlessx
andy
have not previous values, which makes sense given whatEvaluate
does. Unfortunately I cannot fix this other issue (or annoyance if you want) without wrapping it all into aDynamicModule
or such, with which the previous issue returns. $\endgroup$ – glS May 17 '15 at 11:00c
to be substituted with the value currently given by the manipulate, which is correctly done with your solution. The problem with it is that ifx
ory
have some previously assigned value that value is immediately substituted in theEvaluate
and the plot is consequently broken. Wrapping the expression in a Module almost fixes this, except for thex
being then written asx$21438
. $\endgroup$ – glS May 17 '15 at 11:43