1
$\begingroup$

I have imported data for several projects {prj1, prj2, ...} from an excel file, in form of {x,y} coordinates of points. I stored these data in variables and I would like to plot them, also having the possibility to "turn on" or "turn off" some of the projects, so to selectively display different projects. I don't seem to get it work and this is what I've done until now:

prj1 = Import[ExcelFile, {"Data", 5, Table[i, {i, 4, 24}], {1, 2}}];

...

Manipulate[ListPlot[{prj1, prj2, prj3}],
  {prj1, {0, 1}, Checkbox},{prj2, {0, 2}, Checkbox},{prj3, {0, 3}, Checkbox}]

I suspect there is a syntax error, but I need your help to find it...

Thanks in advance.

Conrad

$\endgroup$
3
  • $\begingroup$ Basically the same question, but the proposed solutions doesn't work for me... so I'm still looking for answers. $\endgroup$
    – Conrad
    Jun 17, 2015 at 12:37
  • 2
    $\begingroup$ Conrad, can you clarify in which ways the solutions proposed in the question linked by @Karsten7. do not work for you? As you say as well, your question and that one sound almost identical... $\endgroup$
    – MarcoB
    Jun 17, 2015 at 12:49
  • $\begingroup$ You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. (You've formatted your code as a quotation.) $\endgroup$
    – Michael E2
    Jun 17, 2015 at 13:53

1 Answer 1

7
$\begingroup$

The first answer to the possible duplicate doesn't seem to work under version 10.1. Therefore here is some similar code, that does work:

prjs = {prj1, prj2, prj3} = RandomReal[#, 100] & /@ {1, 2, 3};

Manipulate[ListPlot[prjs[[projectNo]], Joined -> True], 
 {{projectNo, {1}}, Range[Length@prjs], ControlType -> CheckboxBar}]

output

$\endgroup$
17
  • $\begingroup$ this is I think better than the accepted answer to the dup. -- If this question gets closed you should move this over there. $\endgroup$
    – george2079
    Jun 17, 2015 at 15:04
  • $\begingroup$ Just by the way, this does throw an error (w/v9) if you un-check all the boxes. Just a minor annoyance. $\endgroup$
    – george2079
    Jun 17, 2015 at 15:06
  • 1
    $\begingroup$ To include PlotLegends and keep fixed ordering of plots: Manipulate[ListPlot[prjs[[projektNr // Sort]], Joined -> True, PlotLegends -> (("prj" <> ToString[#]) & /@ (projektNr // Sort))], {{projektNr, {1}}, Range[3], ControlType -> CheckboxBar}]. @george2079 - with v10.1 on my Mac, I do not get an error when all boxes are un-checked -- just an empty plot. $\endgroup$
    – Bob Hanlon
    Jun 17, 2015 at 15:15
  • $\begingroup$ @george2079 To generate an empty plot in v9 when all boxes are unchecked, one can use something like ListPlot[prjs[[projectNo /. {} -> {0}]], Joined -> True]. $\endgroup$
    – Karsten7
    Jun 17, 2015 at 15:41
  • $\begingroup$ @Karsten 7. Yes, this way works for me! Maybe is there a way to put the names of projects near Checkboxes (for example "prj1", prj2", etc), instead of numbers ? $\endgroup$
    – Conrad
    Jun 18, 2015 at 11:54

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