Zoom in settings resets automatically when new data value are added

3 views (last 30 days)
I am trying to plot a real time data from a hardware. I want new data values to be plotted and connected to previous data points.
So I am using animatedline() addpoints() command to plot new points and the plot looks good.
When I perform vertical zoom in to see the change in data, the zoom options resets automatically when it adds a new datapoint. I want the zoom in to be enabled till I manually hit the zoom out button.
How could i hold the zoom settings when new data pionts are added in the graph?
Thank you for any help.
  2 Comments
jagadeeshwar tabjula
jagadeeshwar tabjula on 6 Dec 2021
Hi Kishore,
I am also looking for the solution to this problem. Please update if you find an answer for it.
Regards
Jagadeeshwar

Sign in to comment.

Accepted Answer

Kishore Kumar
Kishore Kumar on 7 Dec 2021
Thank you jagadeeshwaran for reminding me to update my answer.
Here I have included a sample code
%test animated line
anim= animatedline('Marker','o');
h1=animatedline('marker','o','color','r');
h2=animatedline('marker','o','color','k');
h3=animatedline('marker','o','color','b');
h4=animatedline('marker','o','color','#7E2F8E');
for i=1:2000
addpoints(h1,i,rand+10);
addpoints(h2,i,rand+20);
addpoints(h3,i,rand+30);
addpoints(h4,i,rand+40);
drawnow limitrate;
if i<100
axis([0 i 0 50])
else
axis([i-100 i 0 50])
end
end
I was trying to update the X axis with last 100 values so that graphs shows a closer view on the latest values.
Pls note that I used
axis([i-100 i 0 50])
command inside for loop which resets the "zoom in" that I perform in plot window.
You could rather use xlim and ylim commands which can force the xlim alone to update with new range of values and the yaxis will be in your control.
%test animated line
anim= animatedline('Marker','o');
h1=animatedline('marker','o','color','r');
h2=animatedline('marker','o','color','k');
h3=animatedline('marker','o','color','b');
h4=animatedline('marker','o','color','#7E2F8E');
ylim([0 50])
for i=1:2000
addpoints(h1,i,rand+10);
addpoints(h2,i,rand+20);
addpoints(h3,i,rand+30);
addpoints(h4,i,rand+40);
drawnow limitrate;
if i<100
xlim([0 i])
else
xlim([i-100 i])
end
end
Here ylimits is initialized outside the for loop and Xlimits are alone updated in the loop. So this will allow to zoom in to any particular y axis range.
Use you use drawnow limitrate to render graphs faster and it also allows user callbacks.

More Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!