Message Boards Message Boards

0
|
5866 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Use list in Chart-function

Posted 10 years ago

How can I simplify this:

BarChart[{pPoäng[2], pPoäng[3], pPoäng[4], pPoäng[5], pPoäng[6], 
  pPoäng[7], pPoäng[8], pPoäng[9], pPoäng[10], pPoäng[11], pPoäng[12],
   pPoäng[13], pPoäng[14], pPoäng[15], pPoäng[16], pPoäng[17], 
  pPoäng[18], pPoäng[19], pPoäng[20], pPoäng[21], pPoäng[22], 
  pPoäng[23], pPoäng[24], pPoäng[25], pPoäng[26], pPoäng[27], 
  pPoäng[28], pPoäng[29], pPoäng[30], pPoäng[31], pPoäng[32], 
  pPoäng[33], pPoäng[34], pPoäng[35], pPoäng[36]}, 
 ChartLabels -> {Range[2, 36]}, AxesLabel -> {X}, ImageSize -> Large]

To something like this:

BarChart[{pPoäng}, ChartLabels -> {Range[2, 36]}, AxesLabel -> {X}, ImageSize -> Large]

I've tried multiple approaches and I either get an empty chart or the error message: "pPoäng is not a valid dataset or list of datasets"

TIA!

POSTED BY: Jim Brännlund
3 Replies

You can try mapping pPoäng:

BarChart[pPoäng /@ Range[2, 26], ChartLabels -> Range[2, 36], AxesLabel -> {X}, ImageSize -> Large]

I wouldn't suggest this, though. If you look at the Information of pPöang, you'll see that it is a function with values it will look up for each number 2..36.

?pPoäng

It would make more sense to use a list which will make it easier to use with BarChart as well but it will require some modifications to your code:

poäng[p_][{x_, x_, x_, y_, y_} /; x != y] := 3 x + 2 y == p;
pPoäng = N[Count[omega, _?(poäng[#])]/ntot] & /@ Range[2, 36];
BarChart[pPoäng, ChartLabels -> Range[2, 36], AxesLabel -> {X}, ImageSize -> Large]

Alternatively, if you have Mathematica 10, you can use pPoäng as an Association. This just requires you to put this line before the Do:

pPoäng = <||>;

Although I would suggest rewriting poäng the same way as above and the Do line as

(pPoäng[#] = N[Count[omega, _?(poäng[#])]/ntot]) & /@ Range[2, 36];

This is to keep p as a local variable.

And then you can draw the chart with

BarChart[pPoäng, ChartLabels -> Range[2, 36], AxesLabel -> {X}, ImageSize -> Large]
POSTED BY: Gerli Jõgeva

What is pPoäng?

POSTED BY: David Reiss
Posted 10 years ago

Sorry, it should be a list with probabilities (floats).

omega = Sort /@ 
   Tuples[{Range[1, 4], Range[1, 6], Range[1, 8], Range[1, 12], 
     Range[1, 20]}];
ntot = Length[omega];
poäng[{x_, x_, x_, y_, y_} /; x != y] := 3 x + 2 y == p (* There are multiple lines like this *))
Do[pPoäng[p] = N[Count[omega, _?(poäng)]/ntot], {p, 2, 36}];
POSTED BY: Jim Brännlund
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract