Connecting Bin centres in Histogram

16 vues (au cours des 30 derniers jours)
Nihar Jariwala
Nihar Jariwala le 6 Juin 2021
Commenté : Image Analyst le 8 Juin 2021
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 commentaires
Manas Minnoor
Manas Minnoor le 6 Juin 2021
Have you tried this?
https://in.mathworks.com/matlabcentral/answers/422000-matlab-histogram-connecting-bin-centers-to-make-a-curve
Nihar Jariwala
Nihar Jariwala le 6 Juin 2021
I have already tried that doesn't seem to work.

Connectez-vous pour commenter.

Réponses (1)

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

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by