How to set YTickLabel in double y-axis plot?
Show older comments
The simplified code is as following:
x=[2,3,4,5,6,7];
y1=[ 1, 1, 1.2, 1.2, 1, 1];
y2=[ 0, 0.01, 0.02, 0.02, 0, 0.01];
fig1 = figure;
[ax,h1,h2] = plotyy(x,y1, x,y2, 'plot');
set(get(ax(1),'YLabel'),'String','y1','fontsize',14)
set(get(ax(2),'YLabel'),'String','y2','fontsize',14)
legend('y1','y2');
xlabel('x')
ylim(ax(1), [0.7, 1.3])
ylim(ax(2), [0, 0.03])
print(fig1, '-dpng', 'test1')
The figure plot is like

I wanted to set the digits of YTick, so I tried something like
set(get(ax(1),'YTick'), [1.00, 1.05, 1.10, 1.15, 1.20]);
set(get(ax(1),'YTickLabel'), [1.00, 1.05, 1.10, 1.15, 1.20]);
or
set(get(ax(1),'YTick'), {'1.00', '1.05', '1.10', '1.15', '1.20']);
set(get(ax(1),'YTickLabel'), {'1.00', '1.05', '1.10', '1.15', '1.20']);
or
set(get(ax(1),'YTick'), str2mat('1.00', '1.05', '1.10', '1.15', '1.20']);
set(get(ax(1),'YTickLabel'), str2mat('1.00', '1.05', '1.10', '1.15', '1.20']);
All went wrong.
So my question is, how to set the digits of y axis label?
And why the left YTick is from 1.0 to 1.2 but leaves all other ticks?
And more generally, how to handle this `gca` properties?
Accepted Answer
More Answers (1)
Mike Garrity
on 22 Mar 2016
Or in R2016a:
ax(1).YAxis.TickLabelFormat = '%.2f';
Categories
Find more on Axis Labels in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!