Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm using Manipulate to visualize three datasets:

Manipulate[ListPlot[WHAT -> what], {what, {dataset1, dataset2, dataset3}}]

Now with this solution I can only plot data for either dataset1, dataset2 or dataset3.

What if I wanted to plot the data for BOTH dataset1 and dataset2 on the same graph? Or for all three datasets? An easy way such as checking boxes corresponding to the datasets would be nice, but I don't know how to integrate this with Manipulate.

share|improve this question
1  
please use a meaningful example instead of dummy names –  rm -rf Mar 25 '13 at 15:47
    
@rm-rf Like WHO -> "is in the first base"? –  belisarius Mar 25 '13 at 15:49
    
I would say that the title is misleading. I understood it in the way that one wants to pick up several numeric values from a list shown in Manipulate. –  Alexei Boulbitch Mar 26 '13 at 9:28
    
@AlexeiBoulbitch that's what I wanted to do in the first place (see my comment below to Jagra's answer), and the question was clear, but then rm-rf told me to delete dummy names which led to more confusion than originally. Dummy names were there for a good reason, my problem comes from the fact that I work on custom functions, if dummy names are "transparent" (eg "myList") I don't see why we should avoid them? –  su1 Mar 26 '13 at 10:15
1  
At this point, I don't have a clue about what you really want Clarifying a question helps everyone. Changing what you want from a question disregards the efforts that people make in producing answers. Two seeming good answers have come for this question. I'd recommend accepting the best of them (mine! mine! Mine! ;-) then giving some more thought to formulating and submitting a second question. –  Jagra Mar 26 '13 at 12:34

3 Answers 3

up vote 3 down vote accepted

A slightly different approach with Checkboxes:

Manipulate[Module[{dataset},
  dataset = RandomReal[#, 100] & /@ {1, 2, 3};
  ListPlot[dataset[[{x, y, z}]], Joined -> True]
  ], {x, {0, 1}, Checkbox}, {y, {0, 2}, Checkbox}, {z, {0, 3}, 
  Checkbox}]

enter image description here

share|improve this answer
    
It doesn't work for me. When x, y, or z are unchecked, they are 0 and dataset[[0]] is List, so ListPlot is passed something like {List, {0.12, ...}, List}, which doesn't work. –  Federico Mar 25 '13 at 17:25
    
@Federico -- Odd. Works perfectly for me with any and all combinations of the different checkboxes. I run version 9. Under what version have you tried this? –  Jagra Mar 25 '13 at 19:19
    
I use version 8. Here is a screenshot. The problem is that in version 8 ListPlot[{_, List, _}] is not allowed. –  Federico Mar 25 '13 at 20:32
    
Works OK here with Mathematica 9.0.1 (under OS X 10.8.3) with all three unchecked as well as all 1-box, 2-box, and 3-box combinations tried, too. –  murray Mar 25 '13 at 21:57
    
@Federico Thanks it works, but because of rm-rf who told me to rephrase my question, actually what I want to do is a little bit different. Let's imagine I have a custom function like: Manipulate[ customFunction[{"myList"}, OPTION -> option], {option, listOfOptions, ControlType -> "SetterBar"}] , but instead of a SetterBar, I'd like a TogglerBar (allowing me to select multiple values at the same time from listOfOptions ). How would I do that? –  su1 Mar 26 '13 at 10:06

here's a guess, is that what you want? (too long for a comment)

data = RandomInteger[10, {3, 10}]

and then you could do:

Manipulate[
ListPlot[what, Joined -> True], {{what, data}, 
MapIndexed[# -> First[#2] &, data], ControlType -> TogglerBar}]

to get:

enter image description here

EDIT (since I still do not know what the OP seeks, I'll keep above)

Based on Federico's comments (thanks!), here's an adjusted version that doesn't break on empty selection and has dedicated colors per "dataset":

Manipulate[
 If[what != {},ListPlot[what, Joined -> True, 
 PlotStyle ->Extract[{Red, Blue, Green}, Position[data, #] & /@ what]], 
 ""], 
 {{what, data}, MapIndexed[# -> First[#2] &, data], 
 ControlType -> TogglerBar}]

Alternatively, to maintain the default colour scheme:

data = RandomReal[{#, # + 1}, 24] & /@ Range[5];
Manipulate[
 If[what =!= {},
  ListLinePlot[data[[what]], PlotStyle -> (ColorData[1] /@ what), ImageSize -> {400, 300}],
  Panel[Style["Select some data!", 18, "TI"],
   Alignment -> Center, Background -> White, Appearance -> None, ImageSize -> {400, 300}]],
 {{what, {1}}, Range@Length[data], ControlType -> TogglerBar}]
share|improve this answer
    
Although very nice, clean and concise, there are two issues: 1) an error is displayed if no dataset is selected; 2) plot lines are subject to colour change (try switching everything off, then click 1, 2, 1). Both of them can be easily fixed. –  Federico Mar 25 '13 at 16:28
    
@Federico: thanks for the input! I wasn't aware that TogglerBar appends the most recently selected choice at the end. As you say "easily fixed", feel free to edit my answer incase you have a better approach - I am sure I must've missed something obvious. –  Pinguin Dirk Mar 25 '13 at 16:47
data = RandomReal[{#, # + 1}, 24] & /@ Range[5];
Manipulate[
 If[what =!= {},
  ListLinePlot[data[[what]], PlotStyle -> (ColorData[1] /@ what), ImageSize -> {400, 300}],
  Panel[Style["Select some data!", 18, "TI"],
   Alignment -> Center, Background -> White, Appearance -> None, ImageSize -> {400, 300}]],
 {{what, {1}}, Range@Length[data], ControlType -> TogglerBar}]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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