1
$\begingroup$

See attached sample code at the bottom of this post.

Under Manipulate, as I step through BarChart data using Take with different start/end positions, the chart of the data is refreshed, but the ChartLabels are not. So BarChart correctly labels the default start/end position data, but when new start/end positions are selected, the BarChart correctly updates the chart for the new data, but the ChartLabels are not refreshed. In the case, where star Names are the ChartLabels, labels still show the previous star names.

Manipulate[
 Switch[whichBarChart,
  4, BarChart[Take[category[[All, 4]], {startPosition, endPosition}],
    ChartLabels -> category[[All, label]],
    BarOrigin -> Left,
    ImageSize -> Large],

where start/end positions are defined as

{{startPosition, 1}, {1, 21, 41, 61, 81, 101, 121, 141, 161, 181, 
  201}},
{{endPosition, 21}, {21, 41, 61, 81, 101, 121, 141, 161, 181, 201, 
  221}},

label is defined as

{{label, 3}, {1 -> "Name", 3 -> "SpectralType", 12 -> "Constellation",
   4 -> "BVColorIndex", 5 -> "Temperature", 6 -> "Mass", 
  7 -> "Luminosity", 8 -> "AbsoluteMagnitude"}},

and whichBarChart is defined as

{{whichBarChart, 6, "Choose BarChart"},
 {4 -> "BVColorIndex", 5 -> "Temperature", 6 -> "Mass", 
  7 -> "Luminosity", 8 -> "AbsoluteMagnitude",
  15 -> "SortTemperature", 16 -> "SortMass", 17 -> "SortLuminosity", 
  18 -> "SortAbsoluteMagnitude"}},

and AstronomicalData categories are defined as

{{category, importAllSubgiant }, {
  importAllClassA -> "ClassA",
  importAllClassB -> "ClassB",
  importAllClassF -> "ClassF",
  importAllClassG -> "ClassG",
  importAllClassM -> "ClassM",
  importAllClassO -> "ClassO",
  importAllSubgiant -> "Subgiant",
  importAllNormalGiant -> "NormalGiant",
  importAllSupergiant -> "Supergiant"}}

Any help would be appreciated. Thanks!

Sample code:

    classA10 = {{"Sirius", 48915, "A1Vm", 0.009`, 1.6`, 2.6`, 
    40.`}, {"Vega", 172167, "A0Vvar", 0.`, 1.7`, 2.9`, 50.`},
   {"Altair", 187642, "A7V", 0.221`, 1.4`, 1.8`, 9.`}, {"Fomalhaut", 
    216956, "A3V", 0.145`, 1.5`, 2.2`, 20.`}, {"Deneb", 197345, 
    "A2Ia", 0.092`, 1.6`, 20.`, 120000.`}, {"Castor", 60179, "A2Vm", 
    0.034`, 1.6`, 2.4`, 30.`}, {"Miaplacidus", 80007, "A2IV", 0.07`, 
    1.6`, 2.8`, 60.`}, {"Menkalinan", 40183, "A2V", 0.076`, 1.6`, 
    2.4`, 30.`}, {"Alhena", 47105, "A0IV", 0.`, 1.7`, 3.5`, 
    90.`}, {"Î\.b4 Velorum", 74956, "A1V", 0.043`, 1.6`, 2.6`, 40.`}};

classB10 = {{"Rigel", 34085, "B8Ia", -0.03`, 2.5`, 23.`, 
200000.`}, {"Achernar", 10144, "B3Vpe", -0.158`, 3.3`, 7.6`, 
3000.`}, {"Hadar", 122451, "B1III", -0.231`, 4.6`, 16.`, 
80000.`}, {"Acrux", 108248, "B0.5IV", -0.243`, 4.8`, 17.`, 
60000.`}, {"Spica", 116658, "B1V", -0.235`, 4.4`, 14.`, 
16000.`}, {"Mimosa", 111123, "B0.5III", -0.238`, 4.8`, 18.`, 
100000.`}, {"Regulus", 87901, "B7V", -0.087`, 2.2`, 4.4`, 
300.`}, {"Adhara", 52089, "B2II", -0.211`, 4.2`, 11.`, 
90000.`}, {"Shaula", 158926, "B1.5IV+...", -0.231`, 4.2`, 13.`, 
30000.`}, {"Bellatrix", 35468, "B2III", -0.224`, 4.2`, 13.`, 
40000.`}};

Manipulate[


Switch[whichBarChart,
  5, BarChart[Take[category[[All, 5]], {startPosition, endPosition}],
    ChartLabels -> category[[All, label]],
    BarOrigin -> Left,
    ImageSize -> Large],
  6, BarChart[
        Take[category[[All, 6]], {startPosition, endPosition}],
    ChartLabels -> category[[All, label]],
    BarOrigin -> Left,
    ImageSize -> Large],
  7, BarChart[Take[category[[All, 7]], {startPosition, endPosition}],
    ChartLabels -> category[[All, label]],
    BarOrigin -> Left,
    ImageSize -> Large]
  ],
 {{startPosition, 1}, {1, 6}},
 {{endPosition, 5}, {5, 10}},
 {{whichBarChart, 6, "Choose BarChart"},
  {5 -> "Temperature", 6 -> "Mass", 7 -> "Luminosity"}},
 {{label, 1}, {1 -> "Name", 3 -> "SpectralType"}},
 {{category, classA10}, {
   classA10 -> "ClassA",
   classB10 -> "ClassB"
   }}
 ]
ListPicker[Dynamic[a],
  {
   classA10 -> "ClassA",
   classB10 -> "ClassB"
   }
  ];
$\endgroup$
  • $\begingroup$ Posted sample code at the bottom of this posting $\endgroup$ – Joseph Karpinski Jul 7 '16 at 19:08
  • $\begingroup$ "In the case, where star Names are the ChartLabels, labels still show the previous star names." Perhaps I am misunderstanding, but isn't that the correct and expected behavior? the "Choose Bar Chart" variable selects which property of the selected stars to plot, but does not influence the selection of a subset of stars, or so it seems to me at least. When you select e.g. another star class, then the names change. Could you clarify the question? $\endgroup$ – MarcoB Jul 7 '16 at 20:40
  • $\begingroup$ Select startPosition 1 and endPosition 5. Notice the star names. Now select startPosition 6 and endPosition 10. The star names did not change. Select startPosition 1 and endPosition 10 to see all star names $\endgroup$ – Joseph Karpinski Jul 7 '16 at 20:46
  • $\begingroup$ What I want to do is build steps of 20 across a sample of 200 for each star category using startPosition and endPosition. 1-20, 21-40, etc show the correct BarChart data, but the star name labels are the same across each step of 20 stars. If I use other fields for label besides Name, like SpectralClass, the same thing happens. Same 20 SpectralClasses across each step of 20. $\endgroup$ – Joseph Karpinski Jul 7 '16 at 20:54
  • $\begingroup$ Additional information, if you change the defaults for startPosition and endPosition from {1,5} to {6,10}, the star names are still those of positions {1,5}. Even if you replace the variables startPosition and endPosition with values{6,10}. While 1-10 works and shows all star names. $\endgroup$ – Joseph Karpinski Jul 7 '16 at 22:04
1
$\begingroup$

This is a refactored / slimmed version of the code in your answer:

Manipulate[
 With[{selected = category[[startPosition ;; endPosition]]},
   BarChart[
     selected[[All, whichBarChart]], 
     ChartLabels -> selected[[All, label]], 
     BarOrigin -> Left, ImageSize -> Large
   ]
 ],
 {{startPosition, 1}, {1, 6}},
 {{endPosition, 5}, {5, 10}},
 {{whichBarChart, 6, "Choose BarChart"}, {5 -> "Temperature", 6 -> "Mass", 7 -> "Luminosity"}},
 {{label, 1}, {1 -> "Name", 3 -> "SpectralType"}},
 {{category, classA10}, {classA10 -> "ClassA", classB10 -> "ClassB"}}
]

The above produces the same output, but avoids repetitive code.

$\endgroup$
  • $\begingroup$ That worked great! Thank you! $\endgroup$ – Joseph Karpinski Jul 8 '16 at 21:09
  • $\begingroup$ Ran into a gotcha. In the full application there are actually two types of charts: $\endgroup$ – Joseph Karpinski Jul 8 '16 at 21:26
  • $\begingroup$ In the full application there are actually two types of charts where 4,5,6,7,8 use the 1st type of BarChart and 15,16,17,18 use a sorted BarChart: $\endgroup$ – Joseph Karpinski Jul 8 '16 at 21:37
  • $\begingroup$ {4 -> "BVColorIndex", 5 -> "Temperature", 6 -> "Mass", 7 -> "Luminosity", 8 -> "AbsoluteMagnitude", 15 -> "SortTemperature", 16 -> "SortMass", 17 -> "SortLuminosity", 18 -> "SortAbsoluteMagnitude"} $\endgroup$ – Joseph Karpinski Jul 8 '16 at 21:38
1
$\begingroup$

Got it. Removed Take and All, replacing with Range[startPosition,endPosition]

Manipulate[
 Switch[whichBarChart,
  5, BarChart[category[[Range[startPosition, endPosition], 5]],
    ChartLabels -> 
    category[[Range[startPosition, endPosition], label]],
    BarOrigin -> Left,
    ImageSize -> Large],
  6, BarChart[category[[Range[startPosition, endPosition], 6]],
    ChartLabels -> 
    category[[Range[startPosition, endPosition], label]],
    BarOrigin -> Left,
    ImageSize -> Large],
  7, BarChart[category[[Range[startPosition, endPosition], 7]],
    ChartLabels -> 
    category[[Range[startPosition, endPosition], label]],
    BarOrigin -> Left,
    ImageSize -> Large]
  ],
 {{startPosition, 1}, {1, 6}},
 {{endPosition, 5}, {5, 10}},
 {{whichBarChart, 6, "Choose BarChart"},
  {5 -> "Temperature", 6 -> "Mass", 7 -> "Luminosity"}},
 {{label, 1}, {1 -> "Name", 3 -> "SpectralType"}},
 {{category, classA10}, {
   classA10 -> "ClassA",
   classB10 -> "ClassB"
   }}
 ]
ListPicker[Dynamic[a],
 {
  classA10 -> "ClassA",
  classB10 -> "ClassB"
  }
 ]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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