Borrar filtros
Borrar filtros

how to create a plot with a histogram in the same graph

24 visualizaciones (últimos 30 días)
Hi,
I want to create a plot of a distribution with a histogram together in the same plot.i'v only been able to plot them separately.
thanks in advance

Respuesta aceptada

Image Analyst
Image Analyst el 11 de Ag. de 2012
The histogram is the distribution. Please explain. If you want to plot a curve - some curve representing the theoretical distribution rather than the actual distribution like what the histogram is, then call "hold on" after you call bar() to plot your histogram and before you call plot() to plot the curve:
bar(binCenters, countData);
hold on;
plot(x, theoreticalCurve, 'bo-');
  3 comentarios
Image Analyst
Image Analyst el 11 de Ag. de 2012
Editada: Image Analyst el 11 de Ag. de 2012
Huh? The numbers you took the histogram of could also be called a "dataset" if you want, as could the counts which is the actual histogram itself. A histogram is a probability density function - the actual density of your actual data, which may be different than the theoretical "dataset" you'd get if you took the histogram of an infinite set of numbers. I'm not sure if you thought your comment clarified things, but it did not. What I mean is have you tried something like this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Generate values from a normal distribution
% with mean 1 and standard deviation 2:
data = 1 + 2 .* randn(10000,1);
[counts binCenters] = hist(data, 50);
bar(binCenters, counts);
grid on;
hold on;
title('Histogram', 'FontSize', fontSize);
xlabel('Value', 'FontSize', fontSize);
ylabel('Number of Counts', 'FontSize', fontSize);
% Enlarge figure to half screen.
set(gcf, 'units','normalized','outerposition',[0 .50 1 .5]);
% Get theoretical curve
x = binCenters;
% Make up some arbitrary curve.
% Note: this is not the theoretically accurate PDF for the randn() function.
theoreticalCurve = [0 5200*diff(erf((x-1)/3))];
% Plot it but also keep the bar chart.
plot(x, theoreticalCurve, 'ro-', 'LineWidth', 2);
deji
deji el 11 de Ag. de 2012
thank you very much.. sorry for not explaining well, i'm trying to check if the data set fits a pareto distribution

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by