How to change the Ytick in the secondary y axis?
10 views (last 30 days)
Show older comments
I have a figure with the following code. How can I add 20 and 80 to the secondary y label? Now it looks like this:
axes1 = axes('Parent',figure(15),'YTick',[8.5 9.5 10.5],'Color',[0 0 0]);
[ax,p1,p2] = plotyy(annual(:,1),annual(:,7),lc2(:,1),lc2(:,2:3));
hold on
set(p1,'LineStyle',':','Marker','v','DisplayName','DO')
set(p2(1),'LineStyle','--','Marker','*','Color',[1 0 0],'DisplayName','Developed')
set(p2(2),'LineStyle','--','Marker','*','Color',[0 0.5 0],'DisplayName','Forest')
[p,~,mu] = polyfit(annual(8:20,1),annual(8:20,7),3)
f = polyval(p,annual(8:20,1),[],mu);
hold on
plot(annual(8:20,1),f,'k','DisplayName','DO Trendline')
xlabel('Time')
ylabel(ax(1),'DO (mg/l)') % left y-axis
ylabel(ax(2),'Area (%)') % right y-axis
ylim(ax(1), [8.5 10.5]);
ylim(ax(2), [0 100]);
legend(axes1,'show');
0 Comments
Accepted Answer
Star Strider
on 17 Apr 2015
I can’t reproduce your plot because I don’t have your data, but this code snippet offers a workable approach:
x = [1992:2012];
y1 = randi([10 35], 1, length(x));
y2 = randi([65 80], 1, length(x));
figure(1)
[ax,p1,p2] = plotyy(x,y1, x,y2);
ylim(ax(2), [0 100]);
set(ax(2), 'YTick',[0, 20, 50, 80, 100])
The last line sets the ticks where you want them and labels them.
0 Comments
More Answers (0)
See Also
Categories
Find more on Labels and Annotations 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!