Connecting Bin centres in Histogram
18 次查看(过去 30 天)
显示 更早的评论
Hi People,
I am plotting an histogram on a semi-log axis (X-axis is logarithmic) while the Y-axis is normal.
I am wanting to connect the bin centres of my histogram and plot a curve from them. I am unable to do so, I have read a number of forums but unable to do it.
I am attaching my code, if someone could suggest me any imputs it would really be helpful.
Regards,
fig1 = figure('Name','a','color','w','position',[Fig.x Fig.y Fig.w Fig.h],'papersize',[Fig.w Fig.h],'paperposition',[0 0 Fig.w Fig.h]);
ax1 = axes;
[~,edges] = histcounts(log10(Duration),20);
h1 = histogram(Duration,10.^edges)
set(gca,'xscale','log');
h1.Normalization = 'probability';
hold on
[~,edges] =histcounts(log10(Duration1),20);
h2 = histogram(Duration1,10.^edges);
hold on;
set(gca,'xscale','log');
h2.Normalization = 'probability';
Nihar.
2 个评论
Manas Minnoor
2021-6-6
Have you tried this?
https://in.mathworks.com/matlabcentral/answers/422000-matlab-histogram-connecting-bin-centers-to-make-a-curve
回答(1 个)
Image Analyst
2021-6-6
Try this. Is it what you want?
clc; % Clear command window.
fprintf('Running %s.m ...\n', mfilename);
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;
% Make up data.
Fig.x = 1;
Fig.y = 1;
Fig.w = 1800;
Fig.h = 1000;
Duration = 200 + randn(1, 1000000);
Duration1 = 190 + randn(1, 1000000);
%------------------------------------------------------------------------------------------------
fig1 = figure('Name','a','color','w','position',[Fig.x Fig.y Fig.w Fig.h],'papersize',[Fig.w Fig.h]);
ax1 = axes;
[~,edges] = histcounts(log10(Duration),20);
h1 = histogram(Duration,10.^edges)
set(gca,'xscale','log');
h1.Normalization = 'probability';
% Plot curve from middle of top of bar to other bars.
hold on
% Get the bin centers as the average between the edges.
binCenters = (h1.BinEdges(1:end-1) + h1.BinEdges(2:end)) / 2;
hold on;
plot(binCenters, h1.Values, 'r.-', 'LineWidth', 2, 'MarkerSize', 40);
[~,edges] =histcounts(log10(Duration1),20);
h2 = histogram(Duration1,10.^edges);
hold on;
set(gca,'xscale','log');
h2.Normalization = 'probability';
% Plot curve from middle of top of bar to other bars.
hold on
% Get the bin centers as the average between the edges.
binCenters = (h2.BinEdges(1:end-1) + h2.BinEdges(2:end)) / 2;
hold on;
plot(binCenters, h2.Values, 'r.-', 'LineWidth', 2, 'MarkerSize', 40);
grid on;
1 个评论
Image Analyst
2021-6-8
Nihar, did that solve it or not? Please answer to respect the time I spent for you.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!