How to add text label to plot referenced to the second y-axis

10 visualizaciones (últimos 30 días)
Mark Wilson
Mark Wilson el 16 de Sept. de 2016
Comentada: Mark Wilson el 16 de Sept. de 2016
I would like to add a text label to my plotyy figure with the y-coordinate of the text(x,y,'string') referenced to the second y-axis. For example, I would like to have a text label at x=1 and y-axis(1)=3000 (text(1,3000,'string')) and another text label at x=2 and y-axis(2)=500, the second instance should be referenced to the second y-axis not the first.
I have tried,
[ax1,h1,h2]=plotyy(x1,y1,x2,y2);
text(ax1(2),xtext,ytext,'string')
"Error using text"
"First two or three arguments must be numeric doubles."
no luck yet, any suggestions would be appreciated. I do not have R2016 or I would have tried yyaxis left and yyaxis right.

Respuestas (1)

Mischa Kim
Mischa Kim el 16 de Sept. de 2016
Mark, what about something like
x = 0:0.01:10;
y1 = exp(-0.05*x).*sin(x);
y2 = exp(-0.5*x).*sin(10*x);
[ax, h1, h2] = plotyy(x, y1, x, y2, 'plot');
text(x(1), y1(1),'string 1')
text(x(end),y2(1),'string 2')
  1 comentario
Mark Wilson
Mark Wilson el 16 de Sept. de 2016
That is exactly what I'm looking for unfortunately it will not work for my application. Here is what I have,
x = 0:0.01:10;
y1 = exp(-0.05*x).*sin(x);
y2 = exp(-0.5*x).*sin(10*x);
y3 = exp(-0.25*x).*sin(5*x);
[ax, h1, h2] = plotyy(x, y1, x, y2, 'scatter');
hold(ax(2),'on')
h3=scatter(ax(2),x,y3,'marker','d','MarkerEdgeColor','[0 0.5 0]');
hold(ax(2),'on')
h4=plot(ax(2),[0 10],[0.3606 0.3603],'k--');
hold(ax(1),'on')
h5=plot(ax(1),[0 10],[0.3606 0.3603],'b-.');
ylim(ax(2),[-0.75 0.75])
text(x(1), y1(1),'string 1')
text(x(end),y2(1),'string 2')
text(4.07,0.3606,' \leftarrowy2=0.3606') %I would like this to be referenced to the 2nd y-axis
legend([h4(1) h5(1)],{'y2=0.3606','y1=0.3606'},'location','southoutside','orientation','horizontal')

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by