Add line curves to histogram in image that has two y axes
7 次查看(过去 30 天)
显示 更早的评论
Is there a way that I can create a histogram that has two y axes, the left axis for the histogram and the right axis for standardized (i.e., domain 0, 1) curves (gamma, in this case) fitted to some portion of the histogram? I can "stairs" the histo data (making it a line, I presume) but following the two y-axis instructions and adding a gamma curve and its "right" y axis causes the stairs to go away (even with "hold on"). I'd prefer to retain the initial histogram and overlay it with the gammas -- but could make due with the stairs. The gamma curves (nine in all) are pre-fitted and I would like to individually overlay and display them, then collectively overlay and display them on the histogram.
Thanks for your help!
LynnBob
Bozeman
0 个评论
采纳的回答
Steven Lord
2019-10-16
Here's an example of creating a pair of axes, one with a histogram and one with a line.
% Sample data
x = randn(1, 1e5);
% Create the histogram on the left axes
yyaxis left
h = histogram(x);
% Make the right axes active
yyaxis right
% Get some data from the histogram
% If you already know the data you want to plot you can skip this step
binvalues = h.BinCounts;
binedges = h.BinEdges;
bincenters = (binedges(1:end-1)+binedges(2:end))/2;
% Plot the line on the right axes (since it's the active axes)
plot(bincenters, binvalues, '--')
You should see that the line on the right axes touches the histogram bars at their centers.
If you are using yyaxis and unable to show both the histogram and the other curve, can you show a small sample of your code that tries to show the other curve?
更多回答(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!