1
$\begingroup$
Manipulate[
    ListPlot[
        {
            Thread[{Range[1, 10, s], Range[1, 10, s]}],
            Range[1, 10, 1]
        },
        Filling -> Axis,
        GridLines -> Automatic,
        GridLinesStyle -> {{Gray, Dotted}, {Gray, Dotted}},
        Frame -> True,
        PlotRange -> {{0.8, 10}, {0, 10}}
    ],
    {s, {1, 0.5, 0.25, 0.125, 0.10}}
]

Default, the s=1 graph is always there (in orange) when clicked on s=0.5, I made it look like the new points in blue are added on.

How could I improve the code, so that when I click on s=0.25, only show the "new points" in a different color? and so on.

For example, when click on s=0.25, the lines from s=1 stay in orange, the lines from s=0.5 stay blue, and the new lines from s=0.25 show in red.

Thanks.

$\endgroup$
2
  • $\begingroup$ By just removing the Range[1, 10, 1] as the second item to be plotted. You plot Thread[{Range[1, 10, s], Range[1, 10, s]}] and Range[1, 10, 1], so of course Range[1, 10, 1] will always be there. Maybe I didn't quite understand what you want to achieve. $\endgroup$
    – Felix
    Feb 9, 2017 at 16:49
  • $\begingroup$ @Felix Sorry if it was not clear, by decreasing s, there are more vertical lines. I just want to show the "new" lines in a different color. $\endgroup$ Feb 9, 2017 at 16:57

2 Answers 2

2
$\begingroup$

I think this might be what you are looking for:

list = {Thread[{Range[1, 10, 1], Range[1, 10, 1]}]};
snow = 1;
Manipulate[
 If[s != snow, 
  PrependTo[list, Thread[{Range[1, 10, s], Range[1, 10, s]}]]; 
  snow = s];
 ListPlot[list, Filling -> Axis, GridLines -> Automatic, 
  GridLinesStyle -> {{Gray, Dotted}, {Gray, Dotted}}, Frame -> True, 
  PlotRange -> {{0.8, 10}, {0, 10}}], {s, {1, 0.5, 0.25, 0.125, 
   0.10}}]

Essentially, list is now storing the history of what you have plotted before and prepends the new data so it's plotted on top.

You may want to use DeleteDuplicates after the PrependTo command.

$\endgroup$
1
$\begingroup$
Manipulate[pos = Position[slist, s, 1, 1][[1, 1]];
 ListPlot[data[[;; pos]], Filling -> Axis, GridLines -> Automatic, 
  Axes -> False, GridLinesStyle -> {{Gray, Dotted}, {Gray, Dotted}}, Frame -> True, 
  PlotRange -> {{0.8, 10}, {0, 10}}], {{s, First@slist}, slist}, 
 Initialization :> {slist = {1, 0.5, 0.25, 0.125, 0.10}; 
   d1 = Transpose /@ Transpose[{#, #}] &@Range[1, 10, slist]; 
   data = FoldList[Complement[#2, #] &, d1]}]

Mathematica graphics

$\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.