PlotLegends makes graph manipulation slow before scanning

I have a small program configured to display three graphs of the same function with different parameters using Manipulate. I would like to mark each function with a parameter value. My starting point was just to show the legend. Adding PlotLegend to the plot causes Mathematica to become unusually 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 PlotLegend should recreate the problem.

My questions: Why is this happening?
What is a good solution or workaround?

+6
source share
2 answers

The problem is that PlotLegend is slow. This has nothing to do with Manipulate . On my PC, ListPlot takes 0.013 seconds without a legend and 0.43 seconds if a legend is added.

As a workaround you can use

 ControlActive[{}, PlotLegend -> {"Blah", "Blarg", "Word"}]] 

not just PlotLegend , to show the legend only when you do not move the sliders.

+7
source

An alternative to Sjoerd's answer might be to restore a legend like Epilog , given that you know that you have three series to build.

+4
source

Source: https://habr.com/ru/post/901851/


All Articles