present 2 histograms in the same X axis values
显示 更早的评论
Hi,
I'm trying to plot 2 histograms in the same x axis. they suppose to have common peaks and I'd like to present them at the same scale so the peaks will overlap. is theres a way to do it?
this is the result I want to achive, but in here I used histcount and it made some other troubles.

5 个评论
Akira Agata
2020-3-26
How about the following example?
sani
2020-3-26
Akira Agata
2020-3-26
Sorry, I'm not clearly understand the point.
As mentioned in the histogram help page, you can switch Y axis with counts <-> PDF by setting 'Normalization' option.
Also, you can change Y axis scale to 'log' by changing the axes handle.
Do these options solve your problem?
回答(1 个)
6 个评论
Akira Agata
2020-3-26
Regarding the figure(2), how about setting the edges, like:
figure(2)
histogram(Ge_table.energy,edges,'Normalization','pdf');
hold on
histogram(Ge_energy,edges,'Normalization','pdf');
set(gca,'YScale','log');
If possible, could you upload your data here so that people here can understand the issue more clearly.
sani
2020-3-26
Akira Agata
2020-3-27
OK, how about adjusting the edge resolution ( = bin width) ?
The following is an example:
load('Ge_energy.mat');
load('Ge_table_energy.mat');
% Set edge resolution (bin width) to 250
edges = 0:250:33000;
figure
histogram(Ge_energy,edges,'Normalization','pdf')
hold on
histogram(Ge_table_e,edges,'Normalization','pdf')
ax = gca;
ax.YScale = 'log';

sani
2020-3-27
Akira Agata
2020-3-27
编辑:Akira Agata
2020-3-27
It's not clear for me what should be done.
Previously, you said that "need both of the histograms to contain the same number of bins and that the peaks but when I wried to set the bins number I got a mess". So I adjusted edge resolution ( = bin width) and (I think) achieved "both of the histograms to contain the same number of bins" avoiding to "got a mess (figure)".
Or, you mean you want plot only details of the histogram around Energy of ~500 [keV] ?
Adam Danz
2020-3-27
I'm also struggling a bit to understand the end goal but from what I understand, you have two data sets, one with n values and the other with m values (n ~= m) and you'd like the histogram bins to match. Is that correct?
If so, try this:
combinedData = [data1(:); data2(:)];
edges = linspace(min(combinedData), max(combinedData), 20); % the 20 is the number of bins
histogram(data1, edges);
hold on
histogram(data2, edges);
类别
在 帮助中心 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


