1
$\begingroup$

In the code below, how can I make 3 separate parameter tables for tup1, tup2, tup3 and plot each function fi of corresponding tupi as in the image below?
Currently there is one one tup table.

enter image description here

f1[a_, b_, c_] := (a x^2 + b x + c)/3;
f2[a_, b_, c_] := (a x^2 + b x + c)^2;
f3[a_, b_, c_] := 3 (a x^2 + b x + c);
tup1 := RandomInteger[5, {6, 3}];
tup2 := RandomInteger[5, {8, 3}];
tup3 := RandomInteger[5, {10, 3}];
tup = Join[tup1, tup2, tup3];
functions1 = f1 @@@ tup1;
functions2 = f2 @@@ tup2;
functions3 = f3 @@@ tup3;
functions = Join[functions1, functions2, functions3];
colors = ColorData[97] /@ Range[Length@functions];
functionswithtooltips = MapThread[Tooltip, {functions, tup}];
plot1 = Plot[Evaluate[functionswithtooltips], {x, 0, 5}, 
   GridLines -> Automatic, ImageSize -> Large, 
   PlotStyle -> Thread[Directive[colors, Opacity[.3], Thin]]];
ttlist = Cases[plot1, _Tooltip, All];
t = Deploy@
  DynamicModule[{n = {1}, hidden = ConstantArray[1, Length@ttlist]}, 
   hidden[[n]] = 2;
   Dynamic[
    Legended[
     Graphics[
      Table[With[{i = i, ind = hidden[[i]]}, 
        Tooltip[{ttlist[[i, 1, 1]], 
          
          DynamicModule[{boxes = {ttlist[[i, 1, 2]], 
              Style[ttlist[[i, 1, 2]], Opacity[1], Thickness[Large]]},
             index = ind, length = 2}, 
           EventHandler[
            Dynamic[
             boxes[[index]]], {"MouseClicked" :> (index = 
                index /. {1 -> 2, 2 -> 1};
               hidden[[i]] = index; 
               n = Flatten[Position[hidden, 2]];), 
             Method -> "Preemptive", PassEventsDown -> True, 
             PassEventsUp -> True}], DynamicModuleValues :> {}]}, 
         ttlist[[i, 2]]]], {i, 1, Length@ttlist}], ImageSize -> 700, 
      AspectRatio -> 1/GoldenRatio, PlotRange -> {{0, 5}, {0, 50}}, 
      Frame -> True, GridLines -> Automatic], 
     TogglerBar[
      Dynamic[n, (n = #; hidden[[All]] = 1; hidden[[n]] = 2) &], 
      MapIndexed[#2[[1]] -> 
         Style[#, 16, Bold, Opacity[1], colors[[#2[[1]]]]] &, tup], 
      Appearance -> "Vertical" -> {Automatic, 4}]]]]
$\endgroup$
4
  • $\begingroup$ i don't understand what you seek. Can you isolate the parts of your code you refer to, and remove all superfluous formatting, dynamic, etc, if not relevant to the question? $\endgroup$ – MarcoB Feb 17 at 22:53
  • $\begingroup$ @MarcoB I want to plot all of them in the same graph but with f1 is plotted with tup1, f2 is plotted with tup2, f3 is plotted with tup3 and then make 3 separate tables for each tuple. Current code plot f1, f2, f3 over all combinations and combine all tup1, tup2, tup2` into one table. $\endgroup$ – anhnha Feb 17 at 23:15
  • $\begingroup$ @MarcoB just for illustration but here is something that I'm trying to do. ibb.co/Bzm6ghN $\endgroup$ – anhnha Feb 17 at 23:29
  • 1
    $\begingroup$ I think you should edit the post and add that picture directly to the post. I think the picture makes it much clearer what you’re looking for. $\endgroup$ – MassDefect Feb 18 at 1:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.