Creating custom values for a histogram

Let's consider the following test case

Clear["Global*"];

Nt = 1000;
data = RandomReal[{0, 1}, Nt];

P0 = Histogram[data, {0, 1, 0.001}, "Probability", ChartStyle -> Gray,
ChartBaseStyle -> EdgeForm[None], Frame -> True,
FrameLabel -> {"x", "P"}, RotateLabel -> False,
LabelStyle -> Directive[FontFamily -> "Helvetica", 20],
PlotRange -> {0, 0.006}, PlotRangePadding -> 0,
PlotRangeClipping -> True, AspectRatio -> 1, ImageSize -> 550]


My question is: how can I multiply the values of the vertical axis by 1000?

EDIT

A part of the actual data can be found here

Then the code is

P0 = Histogram[d0, {0, 2 \[Pi], 0.001}, "Probability",
ChartStyle -> Gray, ChartBaseStyle -> EdgeForm[None], Frame -> True,
FrameLabel -> {"\[Theta]", "P"}, RotateLabel -> False,
LabelStyle -> Directive[FontFamily -> "Helvetica", 20],
PlotRange -> {0, 0.0012}, PlotRangePadding -> 0,
PlotRangeClipping -> True, AspectRatio -> 1, ImageSize -> 550]

• I'm curious: why would you want such a display? It seems not to summarize the data very well. In fact, it looks like a way to compact table a table of numbers and observed frequencies but again not so much of a summary.
– JimB
Jun 9, 2019 at 18:08
• Doesn't using "Count" instead of "Probability" do what you want? I'm assuming that the multiplier of 1,000 is because Nt = 1000.
– JimB
Jun 9, 2019 at 18:09

You can use a custom height function (you also need to change the plot range accordingly). The height function pure function takes a list of counts as the second argument, so to compute 1000 times the probability you just use:

1000 #2/Total[#2]&


Changing the plot range to 1000 times the previous plot range yields:

Histogram[
data,
{0,1,0.001},
1000 #2/Total[#2]&,
PlotRange->{0,6},
ChartStyle->Gray,ChartBaseStyle->EdgeForm[None],Frame->True,FrameLabel->{"x","P"},
RotateLabel->False,LabelStyle->Directive[FontFamily->"Helvetica",20],
]


• When I apply this method to my actual data I get the following error message: Power::infy: Infinite expression 1/0 encountered. Jun 9, 2019 at 14:56
• @Vaggelis_Z What gets echoed when you use 1000 Echo[#2]/Total[#2]& instead? Jun 9, 2019 at 14:58
• A lot of zeroes. Jun 9, 2019 at 15:00
• @Vaggelis_Z What does the Histogram look like when you use "Probability" instead? Jun 9, 2019 at 15:02
• Please see my edit. Jun 9, 2019 at 15:12

If you look at P0 // InputForm you will see that the graphics are a series of rectangles.

For this example (with PlotRange->All) you can replace the rectangles with the following rule.

P0 /. Rectangle[{x1_Real, 0}, {x2_Real, y_Real}, "RoundingRadius" -> 0] ->
Rectangle[{x1,      0}, {x2,      1000*y}, "RoundingRadius" -> 0]


which results in

• And what if the original histogram has a specific range, such as PlotRange -> {0, 0.001}? Jun 9, 2019 at 14:08

Since the desired transformation is linear we can simply rescale the tick labels (using ChartingFindTicks) for the vertical axis without having to worry about modifying the third argument of Histogram:

 Row[{Show[P0, ImagePadding -> Scaled[.15]],
Show[P0,
FrameTicks -> {{ChartingFindTicks[{0, 1}, {0, 1000}], Automatic},
{Automatic, Automatic}},


Note: The option ImagePadding->Scaled[.15] is added so that the image sizes of the two objects in Row are the same (Without it, because of different label sizes, the sizes of the plot areas will be different).

If the multiplication by 1,000 is because Nt = 1000, then using Automatic or "Count" will get you what you want. (If you want an arbitrary multiplicative constant other than the value of Nt - and are not interested in using "Density", then it might help if you might give a rationale for doing so.)

Nt = 1000;
data = RandomReal[{0, 1}, Nt];

Histogram[data, {0, 1, 0.001}, Automatic, ChartStyle -> Gray,
ChartBaseStyle -> EdgeForm[None], Frame -> True,
FrameLabel -> {"x", "P"}, RotateLabel -> False,
LabelStyle -> Directive[FontFamily -> "Helvetica", 20],
PlotRange -> {0, 6}, PlotRangePadding -> 0,
PlotRangeClipping -> True, AspectRatio -> 1, ImageSize -> 550]


I don't see that this is a particular useful display of the data. You might want to try SmoothKernelDistribution instead (but using the "Bounded"` option if your real data is bounded on the left and/or right).