问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/8189742/plotlegends-makes-manipulate-ing-graphs-slow-to-a-crawl