How to plot second graph with second axis with animated line?

8 ビュー (過去 30 日間)
BananaBandana
BananaBandana 2019 年 10 月 11 日
編集済み: Adam Danz 2020 年 1 月 28 日
Hello Friends!
I have created a simulation which generates plots using the animated line function. I already have two lines in one plot, but the problem is, the other
is not really visible because the values are too small compared to the other. Is it possible to create a second animated line in the same plot, but values of the
second line refer to a second y-Axis on the right side of the plot? So then the second line would be clearly visible.
Thanks a lot in advance!
  3 件のコメント
BananaBandana
BananaBandana 2019 年 10 月 12 日
Yes, of course, I always google before I ask a question in this forum ;-)
Maybe I oversee something, but it is nowhere stated, how to do this for an animated plot/animated line. My Problem is, that I need 2 graphs in one plot, but the values of both of them are completely different, and therefore I need 2 y-axis
Michal
Michal 2019 年 10 月 15 日
As far as I can tell it should work with animatedline:
yyaxis left
animatedline(x1,y1)
ylim([MIN,MAX]) % you can set y-axis limits of the left axis
yyaxis right
animatedline(x2,y2)
ylim([MIN,MAX]) % you can set y-axis limits of the right axis
Would you be able to share some of your code for your animated line? I have a feeling you might need something more complex than what I suggested above.

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

採用された回答

Adam Danz
Adam Danz 2019 年 10 月 15 日
編集済み: Adam Danz 2020 年 1 月 28 日
Add the animatedline object after you define the 2nd axis with yyaxis. Then you can set the color of the animated object to the axis color.
Here's a functional demo that animates a line on both the left and right axes
% Create the data
x = linspace(0,10);
y = sin(3*x);
z = sin(3*x).*exp(0.5*x);
% Set up the left axis
yyaxis left
axl = gca(); % handle to left axis
h1 = animatedline('color',axl.YAxis(1).Color); % after yyaxis left; set to axis color.
ylim([-1 1]) % set limits before animation
xlim([1 10]) % set limits before animation
% set up the right axis
yyaxis right
axr = gca(); % handle to right axis
h2 = animatedline('color',axr.YAxis(2).Color); % after yyaxis right; set to axis color.
ylim([-150 150]) % set limits before animation
% Animate
for i = 1:numel(x)
addpoints(h1,x(i),y(i));
addpoints(h2,x(i),z(i));
drawnow
end
See this answer for more animation options and demos.

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by