フィルターのクリア

Connecting Bin centres in Histogram

18 ビュー (過去 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 Center および File ExchangeData Distribution Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by