Plot histograms of two samples as plots

5 ビュー (過去 30 日間)
Gina Carts
Gina Carts 2019 年 4 月 30 日
コメント済み: Adam Danz 2019 年 5 月 28 日
I would like to plot the histograms of two samples as a line plot.
I've been using the histograms functions but this is not what I want. I would like the histogram to be a plot rather than histogram with boxes.
I would also like to plot the line plot of each sample in the same plot but using different colour. I would also like to fix the x- and y-axis.
Can someone help with this?

採用された回答

Adam Danz
Adam Danz 2019 年 4 月 30 日
編集済み: Adam Danz 2019 年 5 月 2 日
"I would like the histogram to be a plot rather than histogram with boxes."
Option 1: Draw line at the center, top of each bar
I interpretted this as a line that traces the height of each bar of the histogram. Or, would you rather plot the probability density function? Here's a demo that achieves the prior.
% Create some fake data
a = randn(1, 10000).*100;
b = randn(1, 10000).*50;
% Create histogram bins
nBins = 50; %number of bins
aEdges= linspace(min(a),max(a), nBins+1);
bEdges= linspace(min(b),max(b), nBins+1);
figure
subplot(2,1,2)
histogram(a,aEdges);
hold on
histogram(b,bEdges);
subplot(2,1,1)
aX = aEdges(2:end)-((aEdges(2)-aEdges(1))/2); %bin centers
aCounts = histcounts(a,aEdges);
plot(aX, aCounts, 'b-s')
hold on
bX = bEdges(2:end)-((bEdges(2)-bEdges(1))/2); %bin centers
bCounts = histcounts(b,bEdges);
plot(bX, bCounts, 'r-s')
" I would also like to fix the x- and y-axis"
I'm not quite sure what you mean but perhaps ylim, xlim would help?
Option 2: Fit the histrogram with a smooth line
See the examples in the documentation
  8 件のコメント
Gina Carts
Gina Carts 2019 年 5 月 28 日
Yea the ylim() works. Is there any way to make the lines on the plot thicker?
Adam Danz
Adam Danz 2019 年 5 月 28 日
plot(x,y,'LineWidth', 3)
% or
h = plot(x,y);
h.LineWidth = 3;
% or
set(h, 'LineWidth', 3)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics and Visualization についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by