Adding text to plot with random inputs
4 ビュー (過去 30 日間)
古いコメントを表示
clc;
clear;
y=20*randn(1,100000)+80;
histogram(y,11)
title('Normal Distribution')
xlabel('Value');
ylabel('Count');
txt={'\mu = 80'};
text(80,3.3*10^4, txt);
txt={'\sigma = 20'};
text(100, 3.3*10^4, txt);
I have code that takes a random input and creates a histogram that always has the mean = 80 and standard deviation =20. My question is how do I add text to the plot so that my text '\sigma = 20' is always above the exact mean, which should be 80. I've chosen a large y value just to prevent the text being inside the bar but I'd like it to be on top of the bar no matter the value. The standard deviation text can go anywhere, but preferably close to the mean text.
0 件のコメント
回答 (2 件)
Arif Hoq
2022 年 2 月 10 日
y=20*randn(1,100000)+80;
histogram(y,11)
title('Normal Distribution')
xlabel('Value');
ylabel('Count');
txt1={'\mu = 80'};
txt2={'\sigma = 20'};
text(80,3.3*10^4, txt1,'HorizontalAlignment','center','VerticalAlignment','top');
text( 80, 3.3*10^4, txt2,'HorizontalAlignment','center','VerticalAlignment','bottom');
0 件のコメント
Walter Roberson
2022 年 2 月 10 日
y=20*randn(1,100000)+80;
histogram(y,11)
title('Normal Distribution')
xlabel('Value');
ylabel('Count');
actual_mu = mean(y);
actual_sigma = std(y);
txtmu = "\mu = " + round(actual_mu,2);
txtsigma = "\sigma = " + round(actual_sigma,2);
text(actual_mu, 3.3*10^4, txtsigma); %yes, sigma is the one placed at mu
text(actual_mu + 20, 3.3*10^4, txtmu);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!