help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Legend troubles


From: Arnaud Miege
Subject: Legend troubles
Date: Mon, 18 Mar 2013 13:59:21 +0000

Hi,

I am trying to create a histogram plot, with a superimposed smooth distribution plot on top (similar to histfit) in Octave 3.6.2. It works well up to the point when I try to add a legend, which it does, but without respecting the colours. The following code:

data = "">
nbins = 20;
[n,xbin]=hist(data,nbins);
mr = mean(data); % Mean
sr = std(data); % Standard deviation
x=(-3*sr+mr:0.1*sr:3*sr+mr)';
[xb,yb] = bar(xbin,n);
y = normpdf(x,mr,sr);
binwidth = xbin(2)-xbin(1);
y = row*y*binwidth;   % Normalization necessary to overplot the histogram.
plot(xb,yb,'b',x,y,'r-');     % Plots density line over histogram.
legend('raw data','normal distribution')

produces (with the Qt graphics toolkit):

Inline images 2

The plot is correct, but the legend is not: both lines are blue. I was expecting the first one to be blue and the second to be red. Obviously in the real application, the data is not necessarily normally distributed, so the idea is to see how far off we are from a normal distribution.

Any suggestions on how to get the legend to display correctly?

Many thanks in advance,

Arnaud

PS: the reasons I am not using histfit are:
  1. It does not work. Line 64 (y = normal_pdf(x,mr,sr.^2);) calls the function normal_pdf which doesn't exist. I think it should be changed to y = normpdf(x,mr,sr);
  2. I want to plot more than just one (normal) distribution on top of the histogram.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]