Filter löschen
Filter löschen

Add a line plot on bar chart

4 Ansichten (letzte 30 Tage)
H-H
H-H am 29 Sep. 2013
Beantwortet: Image Analyst am 29 Sep. 2013
Hi there, I want to add a Normal distribution function (mean=0.5, sd=0.167) as a line on top of this bar chart. I want to keep the same x-axis and Y-axis. and I don't want to Fit the PDF. This is my bar chart construction in bellow. Can you please comment? Thanks.
X1 = [ 1.994711e-02 5.978008e-02 9.961305e-02 1.394460e-01 1.792790e-01 2.191120e-01 2.589449e-01 2.987779e-01 3.386109e-01 3.784439e-01 4.182768e-01 4.581098e-01 4.979428e-01 5.377757e-01 5.776087e-01 6.174417e-01 6.572747e-01 6.971076e-01 7.369406e-01 7.767736e-01 8.166066e-01 8.564395e-01 8.962725e-01 9.361055e-01 9.759384e-01 ]; N1 = [ 6.910998e-02 6.358135e-02 5.939631e-02 5.477412e-02 5.035550e-02 4.661832e-02 4.306543e-02 3.973325e-02 3.640108e-02 3.456677e-02 3.427749e-02 3.374177e-02 3.321890e-02 3.323176e-02 3.361105e-02 3.347819e-02 3.356605e-02 3.354248e-02 3.344391e-02 3.361105e-02 3.341176e-02 3.348248e-02 3.306890e-02 3.352534e-02 3.318676e-02 ]; y=bar(X1,N1,1.0); xmin = min(X1); xmax = max(X1); xwid = xmax - xmin; xmin = xmin - 0.5 * xwid / 25; xmax = xmax + 0.5 * xwid / 25; ymax = max(N1); axis([xmin xmax 0 ymax]) xlabel('X1','FontWeight','bold','FontSize',12) ylabel('Probabilities','FontWeight','bold','FontSize',12) set(gca,'linewidth',2) set(gca,'fontweight','bold') set(gca,'fontsize',12)

Akzeptierte Antwort

Image Analyst
Image Analyst am 29 Sep. 2013
Try this:
X1 = [
1.994711e-02 5.978008e-02 9.961305e-02 1.394460e-01 1.792790e-01 2.191120e-01 2.589449e-01 2.987779e-01 3.386109e-01 3.784439e-01 4.182768e-01 4.581098e-01 4.979428e-01 5.377757e-01 5.776087e-01 6.174417e-01 6.572747e-01 6.971076e-01 7.369406e-01 7.767736e-01 8.166066e-01 8.564395e-01 8.962725e-01 9.361055e-01 9.759384e-01 ];
N1 = [
6.910998e-02 6.358135e-02 5.939631e-02 5.477412e-02 5.035550e-02 4.661832e-02 4.306543e-02 3.973325e-02 3.640108e-02 3.456677e-02 3.427749e-02 3.374177e-02 3.321890e-02 3.323176e-02 3.361105e-02 3.347819e-02 3.356605e-02 3.354248e-02 3.344391e-02 3.361105e-02 3.341176e-02 3.348248e-02 3.306890e-02 3.352534e-02 3.318676e-02 ];
% Plot N1
subplot(3,1,1);
y=bar(X1,N1,1.0);
xmin = min(X1);
xmax = max(X1);
xwid = xmax - xmin;
xmin = xmin - 0.5 * xwid / 25;
xmax = xmax + 0.5 * xwid / 25;
ymax = max(N1);
axis([xmin xmax 0 ymax])
xlabel('X1','FontWeight','bold','FontSize',12)
ylabel('Probabilities','FontWeight','bold','FontSize',12)
set(gca,'linewidth',2)
set(gca,'fontweight','bold')
set(gca,'fontsize',12)
% Plot Gaussian
subplot(3,1,2);
x = X1; %linspace(0, 1, length(X1));
g = exp(-(x-0.5).^2/(2*0.167^2))
% Make g the same height at the tallest N1
plot(x, g, 'r-', 'LineWidth', 3);
grid on;
% Plot both
subplot(3,1,3);
bar(X1,N1,1.0);
hold on;
% Make g the same height at the tallest N1
g = g * max(N1);
plot(x, g, 'r-', 'LineWidth', 3);
grid on;

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by