Group Abstract Group Abstract

Message Boards Message Boards

[?] Plot probability distribution?

Posted 8 years ago

Hi All. I have an issue with plotting. The following data shows the probability distribution of a random variable X (here 25/81, 30/81 etc are the probabilities):

data={{1,25?81},{2,30?81},{4,19?81},{8,6?81},{16,1?81}}

I would like to plot a bar-chart like in the image below. However, using for example, Histogram[WeightedData @@ Transpose[data], Length[data]] command I get a plot which is different. I would like the one where the bars are spaced like in the image below. I appreciate your help.

enter image description here

POSTED BY: Alex Token
10 Replies
Posted 8 years ago
POSTED BY: Alex Token
Posted 8 years ago
POSTED BY: Alex Token

Yes, I think so. I have done a simple modification in the code which must exclude the trouble. Try this:

data = {{1, 25/81}, {2, 30/81}, {4, 19/81}, {8, 6/81}, {16, 1/81}};
len = Length[data];
data1 = {Range[data[[1, 1]], data[[len, 1]]], Table[0, data[[len, 1]]]};
Do[data1[[2, data[[i, 1]]]] = data[[i, 2]], {i, len}];
BarChart[data1[[2]], ChartLabels -> data1[[1]], Frame -> True, GridLines -> {None, Automatic}]
Posted 8 years ago

Dear Valeriu. I am using Wolfram 10.0. Maybe this is the issue? Thank you.

POSTED BY: Alex Token

Dear Alex,

I have executed the code from your file. The result you can see below:

enter image description here

What is the version of your Wolfram Mathematica?

Posted 8 years ago

Thank you for your reply. I copied and pasted the code but it does not produce the same outcome as in yours. I attach here a mat file. Thank you.

Attachments:
POSTED BY: Alex Token
Posted 8 years ago
POSTED BY: Alex Token
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard