Adjust count values in histogram
Show older comments
Hello
I have a vector of temperature values taken in 1 second increments. I want to use the "histogram" command to show in which time period which temperatures were measured. This will work correctly for the time unit seconds. But I want to display these seconds (y-values) now in hours. I don't know how to change the "Values" attribute to do this.
Thanks for the help.
8 Comments
On histogram you expect to see the distribution of data itself, so I'm not sure what you exactly mean by second or hr. Say you have a vector of temp for temperature measured at different time points (as you said, in 1 sec intervals):
temp = randsample(1:1:100, 1e4, true, [linspace(eps, 1-eps, 50), flip(linspace(eps, 1-eps, 50))]);
histogram(temp)
xlabel("Temperature")
Sebastian
on 1 Mar 2022
"I see from it that the temperature value 40°C was measured in a period of about 500 seconds"
No! it shows the measurement count within the bin. For instance the image below shows there are 482 temperature values within the range (bin) of [39, 42):

If you're interested to change y-axis, see histogram property Normalization: https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.histogram-properties.html
Adam Danz
on 1 Mar 2022
> Let's use your histogram as an example: I see from it that the temperature value 40°C was measured in a period of about 500 seconds.
As @Ive J mentioned, this is not what the histogram is showing. The y axis of histograms are typically counts, probabilities, frequencies, etc. The y-axis shows the density of values within each x-bin.
Perhaps you could elaborate on your goal and provide an example.
jessupj
on 1 Mar 2022
I think you'd want to do something like this
ggg = gca;
ggg.YTickLabels = cellfun(@str2num, ggg.YTickLabels )/3600
that converts the current yticklabel strings to numbers and scales them by some factor. of course, this will be ugly without specificying precision.
Adam Danz
on 2 Mar 2022
Accepted Answer
More Answers (1)
David Hill
on 1 Mar 2022
Use normalization (probability) to get what you want.
temp = randsample(1:1:100, 1e4, true, [linspace(eps, 1-eps, 50), flip(linspace(eps, 1-eps, 50))]);
histogram(temp,'Normalization','probability')
xlabel("Temperature")
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
