Effacer les filtres
Effacer les filtres

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

24 vues (au cours des 30 derniers jours)
deji
deji le 11 Août 2012
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

Réponse acceptée

Image Analyst
Image Analyst le 11 Août 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 commentaires
Image Analyst
Image Analyst le 11 Août 2012
Modifié(e) : Image Analyst le 11 Août 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 le 11 Août 2012
thank you very much.. sorry for not explaining well, i'm trying to check if the data set fits a pareto distribution

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by