Plot 2 Y axes using GUI and Handle structures
2 次查看(过去 30 天)
显示 更早的评论
I am using handle structures to create my figures and want two Y axes. When I create the second y axis it deletes the first. What I am trying to achieve is a histogram (left axis) and CDF (right axis) on the one plot.
What am I missing in my code? Thanks.
hs.A_PT_PnLPct = axes;
hs.A_PT_PnLPct.Parent = hs.Fig;
hs.A_PT_PnLPct.Title.String = 'Returns';
hs.A_PT_PnLPct.FontSize = 8;
hs.A_PT_PnLPct.Title.FontSize = 10;
hs.A_PT_PnLPct.XLabel.String = 'Return %';
hs.A_PT_PnLPct.YAxisLocation = 'Left';
hs.A_PT_PnLPct.YLabel.String = 'Frequency';
hs.A_PT_PnLPct.Units = 'pixels';
hs.A_PT_PnLPct.XGrid = 'on';
hs.A_PT_PnLPct.YGrid = 'on';
hold( hs.A_PT_PnLPct, 'on' );
hs.A_PT_PnLPct.YAxisLocation = 'Right';
hs.A_PT_PnLPct.YLabel.String = 'CDF';
hs.A_PT_PnLPct.Position = [990 430 300 300];
0 个评论
回答(1 个)
Josh
2017-2-28
I think you might have to make two axes objects on top of each other. Plot your histogram on one and the CDF on the other.
% Create axes
a1 = axes; a2 = axes;
% Ensure that axes are overlayed:
a2.Position = a1.Position;
% Move second y-axis to the right:
a2.YAxisLocation='Right';
% Turn off second x-axs:
a2.XAxis.Visible='off';
% Set the second axis (the one on top) to have a clear background:
a2.Color='none';
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!