How to change the Ytick in the secondary y axis?

11 visualizaciones (últimos 30 días)
Fred
Fred el 17 de Abr. de 2015
Respondida: Star Strider el 17 de Abr. de 2015
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');

Respuesta aceptada

Star Strider
Star Strider el 17 de Abr. de 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.

Más respuestas (0)

Categorías

Más información sobre Labels and Annotations en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by