0
$\begingroup$

I'd need to write an interactive plot. I have some function I defined and some point lists I get from external data file. I'd need to see those data along with my functions, and I know how to do that. However I would also like to have a checklist, and by clicking over each button I should be able to show/hide a function or a data point set.

I don't need the full code, just a hint about how to get a checklist, and how to make it dynamically affect the function I'm plotting would be great!

$\endgroup$

1 Answer 1

3
$\begingroup$
SeedRandom[42];
{set6, set9} = RandomReal[{-1, 1}, {#, 2}] & /@ {6, 9};
{p6, p9} = Interpolation[#, Method -> "Spline"] & /@ {set6, set9};
With[{in = Indeterminate}, 
 Manipulate[Show[Quiet@
    Plot[{If[t6p, p6@x, in], If[t9p, p9@x, in], in}, {x, -1, 1}, PlotRange -> {{-1, 1}, 5 {-1, 1}}], 
    ListPlot[{If[t6s, set6, in], If[t9s, set9, in], in}, PlotStyle -> PointSize[Large]]],
  Grid[{{Control[{t6s, {True, False}}], Spacer[10], Control[{t6p, {True, False}}]}, 
        {Control[{t9s, {True, False}}], Spacer[10], Control[{t9p, {True, False}}]}}]]]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ "just a hint" :) $\endgroup$ Commented Dec 27, 2013 at 17:23
  • 1
    $\begingroup$ @cormullion It may seem simple for an experienced user, but there are a lot of possible pitfalls in that code for a novice. I preferred to post a small working example than to elaborate on the caveats. Do you think it's out of place? $\endgroup$ Commented Dec 27, 2013 at 17:27
  • 1
    $\begingroup$ No not at all! :) The great thing about this site is how you experts give so much more than the minimum necessary... $\endgroup$ Commented Dec 27, 2013 at 18:50

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.