overlay 2 histograms one over the other

3 次查看(过去 30 天)
Hello,
I'm ploting my data as histograms (there are 2 data sets, one is the original and the other is the the same set that been processed- basicly the relation between them is the X axis)
I want to present the 2 sets one over the other, but what I'm getting is this
how can I make the picks to be one over the other? as they are in the real data sets
another thing, is theres a way to present histogram as semi logarithmic with respect to Y axis?
Ge_energy = Ge_energy*0.3;
Ge_table.energy = Ge_table.energy*0.3;
figure(2)
histogram(Ge_energy,'DisplayStyle','stairs','BinWidth',0.1)
hold on
histogram(Ge_table.energy,'DisplayStyle','stairs','BinWidth',0.1)

回答(1 个)

Vedant Shah
Vedant Shah 2025-4-11
Hi @sani,
To present the sets one over the other as they are in real datasets, the bin edges need to be aligned. So, we can use common binedges for both the plots. The BinEdges can be specified as follows:
binEdges = 0:0.1:130;
histogram(Ge_energy, 'BinEdges', binEdges, 'DisplayStyle', 'stairs');
Ensure that the same BinEdges are used for the other histogram as well.
Additionally, to set the Y-axis to a logarithmic scale, you can use the set function as shown below:
set(gca, 'YScale', 'log');
For more information about the BinEdges attribute or the set function, please refer to the documentation using the following commands in the MATLAB command line:
web(fullfile(docroot, "/matlab/ref/set.html"));
web(fullfile(docroot,"/matlab/ref/matlab.graphics.chart.primitive.histogram.html"));

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by