0
$\begingroup$

Suppose I am provided with two data lists. (Assume for the moment that they are lists of integers.) I would like a function that generates bar charts that I can manipulate.

Here is what I have:

f[dL1_List, dL2_List] :=
  Module[{dL1SymList, dL2SymList},
   dL1SymList = (Symbol["dL1" <> ToString[#]] &) /@ dL1;
   dL2SymList = (Symbol["dL2" <> ToString[#]] &) /@ dL2;
   (
     Manipulate[Grid[{
         {
          BarChart[dL1SymList, PlotLabel -> "dL1"],
          BarChart[dL2SymList, PlotLabel -> "dL2"]
          }
         }], ##] &
     ) @@
    Join[
     MapThread[({{#1, #2}, 0.0, 10*#2} &), {dL1SymList, dL1}],
     MapThread[({{#1, #2}, 0.0, 10*#2} &), {dL2SymList, dL2}]
     ]
   ];

f[Range[1, 5], Range[1, 5]]

However, while this does not produce any error, it does not display bar graphs either. Can you please help me understand where I am going wrong?

Thanks in advance for your help.

$\endgroup$

1 Answer 1

1
$\begingroup$

Just to get it working: you need to read and fully grok the documentation for Manipulate... it explains in detail why constructs like this are used, and the changes in "expected" behaviors within Manipulate.

f[dL1_List, dL2_List] := 
  Module[{dL1SymList, dL2SymList}, 
   dL1SymList = (Symbol["dL1" <> ToString[#]] &) /@ dL1;
   dL2SymList = (Symbol["dL2" <> ToString[#]] &) /@ dL2;
   (With[{dL1SymList = dL1SymList, dL2SymList = dL2SymList}, 
       Manipulate[
        Grid[{{BarChart[dL1SymList, PlotLabel -> "dL1"], 
           BarChart[dL2SymList, PlotLabel -> "dL2"]}}], ##]] &) @@ 
    Join[MapThread[({{#1, #2}, 0.0, 10*#2} &), {dL1SymList, dL1}], 
     MapThread[({{#1, #2}, 0.0, 10*#2} &), {dL2SymList, dL2}]]];

f[Range[1, 3], Range[1, 2]]

enter image description here

$\endgroup$
0

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.