I have a short program set up to display three plots of the same function with different parameters using Manipulate. I'd like to label each function with the value of the parameter. My starting point was to just get a legend to show up at all. Adding a PlotLegend to the plot causes Mathematica to become unusably slow.
My code is:
Needs["PlotLegends`"]
Manipulate[
UemaxOverUe = ((VA/Vphs)^2 (2 p - 1) + 1 - Ves0/Vphs - 2)/((VA/Vphs)^2 - (1 - Ves0/Vphs));
UemaxOverUe2 = ((VA/Vphs)^2 (2 p - 1) + 1 - Ves02/Vphs - 2)/((VA/Vphs)^2 - (1 - Ves02/Vphs));
UemaxOverUe3 = ((VA/Vphs)^2 (2 p - 1) + 1 - Ves03/Vphs - 2)/((VA/Vphs)^2 - (1 - Ves03/Vphs));
ListPlot[{
Table[{Vphs/VA, 1/UemaxOverUe}, {Vphs, .001 VA, VA, .01 VA}],
Table[{Vphs/VA, 1/UemaxOverUe2}, {Vphs, .001 VA, VA, .01 VA}],
Table[{Vphs/VA, 1/UemaxOverUe3}, {Vphs, .001 VA, VA, .01 VA}]},
AxesLabel -> {"Vphs/VA", "Ne/NeMax"}, Joined -> True(*,
PlotLegend->{"Blah","Blarg","Word"}*)],
{{p, 1}, 0, 5},
{{Ves0, -2 VA}, -10 VA, 10 VA, .1 VA},
{{Ves02, -2 VA}, -10 VA, 10 VA, .1 VA},
{{Ves03, -2 VA}, -10 VA, 10 VA, .1 VA}
]
Uncommenting the PlotLegend
should recreate the problem.
My questions are:
Why does this happen?
What is a good solution, or workaround?
The problem seems to be that PlotLegend is just slow. It hasn't got anything to do with Manipulate
. On my PC The ListPlot
takes 0.013 s without a legend and 0.43 second if a legend is added.
As a workaround you could use
ControlActive[{}, PlotLegend -> {"Blah", "Blarg", "Word"}]]
instead of just the PlotLegend
to show the legend only when you're not moving the sliders.
An alternative to Sjoerd's answer might be to reconstruct the legend as an Epilog
, given that you know you have three series to plot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With