Connecting Bin centres in Histogram

조회 수: 17 (최근 30일)
Nihar Jariwala
Nihar Jariwala 2021년 6월 6일
댓글: Image Analyst 2021년 6월 8일
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
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
Nihar Jariwala
Nihar Jariwala 2021년 6월 6일
I have already tried that doesn't seem to work.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
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
Image Analyst 2021년 6월 8일
Nihar, did that solve it or not? Please answer to respect the time I spent for you.

댓글을 달려면 로그인하십시오.

카테고리

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