1
$\begingroup$

Assume that I have a graphList as shown below (a simple working example).

graphList = 
  Show[Plot[x^2, {x, 0, 3.5}], 
     ListPlot[RandomInteger[{0, 10}, #], 
      PlotStyle -> Directive[Orange, PointSize[0.05]]], 
     PlotLabel -> Style[#, Red, Bold, 20]] & /@ Range[10];

enter image description here

Now, imagine that I want to manually go through each graph one by one and save interesting graphs by positions into separate lists. For example:

interestingList1 = {1, 3, 8};
interestingList2 = {4, 6};

However, I don't want to manually write down the numbers like that, as it is easy to make errors by miswriting the numbers and it's probaly a bit slow as well. So, I'm thinking about a method to add something to the graph (button or something) that allows me to save positions by simply clicking/pressing a button or using a similar method to add them to interestingList1 and interestingList2, which I can select. A button is just my idea. If you know a better way to do it, please suggest as well.

How can I do that?

$\endgroup$

2 Answers 2

2
$\begingroup$

You may store the different plots and then use "AppendTo" to fill the list with the chosen plots like:

graphList = {}; 
Column[{graph[#] = 
     Show[Plot[x^2, {x, 0, 3.5}], 
      ListPlot[RandomInteger[{0, 10}, #], 
       PlotStyle -> Directive[Orange, PointSize[0.05]]], 
      PlotLabel -> Style[#, Red, Bold, 20]], 
    Button["Save", AppendTo[graphList, graph[#]]]}] & /@ Range[10]

Dynamic[graphList]

enter image description here

$\endgroup$
2
$\begingroup$

We can use a combination of SetterBar, TogglerBar and PaneSelector

ClearAll[tB, indexSelector]

tB[Dynamic[$w_], gl_, nc_ : 5] := TogglerBar[Dynamic[$w], 
   Thread[Range[Length @ gl] -> gl], 
   Appearance -> "Horizontal" -> {Automatic, nc}]

SetAttributes[indexSelector, HoldFirst]

indexSelector[intl_, graphlst_, nc_ : 5] := (ClearAll @ intl;
   Deploy @ 
   DynamicModule[{$z, $il = Range @ Length @ intl, lbls = ToString /@ intl}, 
    Column[{SetterBar[Dynamic[$z], MapThread[Rule, {$il, lbls}]], 
      PaneSelector[
        Table[With[{$w = intl[[$i]]}, tB[Dynamic[$w], graphlst, nc]], 
         {$i, 1, Length @ intl}], 
        Dynamic[$z]]}, 
      Alignment -> Center]])

Examples:

graphList = Show[Plot[x^2, {x, 0, 3.5}], 
  ListPlot[RandomInteger[{0, 10}, #], 
    PlotStyle -> Directive[Orange, PointSize[0.05]]],
  PlotLabel -> Style[#, Red, Bold, 20]] & /@ Range[10];


indexSelector[{interestingList1, interestingList2, interestingList3}, 
  graphList]

Dynamic[{interestingList1, interestingList2, interestingList3}]

enter image description here

For more responsive interaction, rasterize the graphics in graphList:

rasterizedGraphList = Rasterize[#, ImageResolution -> 100, Background -> None, 
     ImageSize -> 180] & /@ graphList;


indexSelector[{interestingList1, interestingList2, interestingList3}, 
  rasterizedGraphList, 4]

Dynamic[{interestingList1, interestingList2, interestingList3}]

enter image description here

Dynamic @ Style[Multicolumn[graphList[[interestingList2]], 2], 
  ImageSizeMultipliers -> {1, 1}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.