How can I get a histogram to display the basket as a percentage in Mathematica?

Currently, I can generate a histogram with y-axis values ​​between 0.0 and 1.0 using hspec "Probability", but I was wondering if it can be displayed as a percentage (this will not change anything) but the y-axis designation).

Here is what I am using now:

Histogram[rawdata, {{0, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}}, "Probability", PlotRange -> {0, 1}] 
+4
source share
1 answer
 rawdata = RandomReal[NormalDistribution[50, 20], 12000]; bins = {Range[0, 100, 10]}; Histogram[rawdata, bins, "Probability", Ticks ->{ First@bins , Table[{.01 i, If[Mod[i , 5] == 0, ToString[i] <> "%", ""]}, {i, 100}]}] 

enter image description here

With BarChart, you also get full control over the shortcuts, and perhaps in some situations this is better:

 BarChart[(Length /@ BinLists[rawdata, bins])/ Length@rawdata 100, ChartLabels -> bins[[1, 2 ;;]], Ticks -> {Automatic, Table[{i, If[Mod[i, 5] == 0, ToString[i] <> "%", ""]}, {i, 1, 100}] }] 

enter image description here

Edit

If you intend to use BinLists[] , remember this slippery detail: (from the help)

In BinLists [data, {xMin, xMax, dx}] elements are placed in bin i when their values ​​satisfy xMin + (i-1) dx <= x <xMin + i dx.

In the form BinLists [data, {{b1, b2, ...}}] bi, at each end there can be -Infinity and + Infinity.

+11
source

All Articles