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

12 ビュー (過去 30 日間)
Mark Wilson
Mark Wilson 2016 年 9 月 16 日
コメント済み: Mark Wilson 2016 年 9 月 16 日
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.

回答 (1 件)

Mischa Kim
Mischa Kim 2016 年 9 月 16 日
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 件のコメント
Mark Wilson
Mark Wilson 2016 年 9 月 16 日
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')

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by