Plot of histogram and probability distribution function.
34 ビュー (過去 30 日間)
古いコメントを表示
I have three columns of data. I am plotting histogram and normal distribution probability density function (pdf) for each column. For one column, I get its histogram and pdf shown by two different colours in plot and I get two indicators in legend. Similarly, I get histogram and pdf for remaining two columns of data. In total, I get 6 indicators with 6 different colors in legend. I want to get histogram and pdf of one column of data with same colour and show indicator only for histogram. Similarly, I want to get histogram and pdf for remaining two columns so that I get three colours for three columns of data.
Thankyou
x = (1:1:100)';
y = (101:1:200)';
z = (201:1:300)';
p1 = fitdist(x,'Normal');
p2 = fitdist(y,'Normal');
p3 = fitdist(z,'Normal');
plot(p1)
hold on
plot(p2)
plot(p3)
legend('5%','5%','10%','10%','15%','15%');
hold off
0 件のコメント
採用された回答
Adam Danz
2024 年 4 月 12 日
編集済み: Adam Danz
2024 年 4 月 12 日
To equate the colors between the histogram and line pairs, access the object handles from the plot output and then set the SeriesIndex property to the same value. See a note at the bottom of this solution to control the color.
To show only the histogram objects in the legend, specify the histogram handles in the legend command. I also defined the legend strings using the DisplayName properties. Note that the fitdist plot will return a 1x2 vector of handles where the first handle is the line object and the second is the histogram.
x = (1:1:100)';
y = (101:1:200)';
z = (201:1:300)';
p1 = fitdist(x,'Normal');
p2 = fitdist(y,'Normal');
p3 = fitdist(z,'Normal');
h1 = plot(p1);
set(h1,'SeriesIndex',1)
h1(2).DisplayName = '5%';
hold on
h2 = plot(p2);
set(h2,'SeriesIndex',2)
h2(2).DisplayName = '10%';
h3 = plot(p3);
set(h3,'SeriesIndex',3)
h3(2).DisplayName = '15%';
legend([h1(2),h2(2),h3(2)]);
hold off
ax = gca();
ax.ColorOrder = [1 0 0; 0 0 1; 1 0 1];
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Histograms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!