Plot 2 Y axes using GUI and Handle structures
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Josh
on 28 Feb 2017
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 Comments
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!