- https://www.mathworks.com/help/matlab/ref/ylim.html
- https://www.mathworks.com/help/matlab/ref/set.html
How can I zoom on a constantly updating animated line (drawnow)?
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi I'm currently working on a project using the draw now library. I am measuring the pressure in a vacuum system via serial communication then plotting the data live using drawnow and an animated line. However since the pressure starts at atmospheric pressure (10^3) then drops to 10^-4 and even lower. This creates an issue since the points at time 0 at atmospheric pressure always stay on the plot so the plot is way to large to see the points at a high vaccuum (10^-4). Is there a way for me to zoom in on the live plot or even create a seperate plot frozen in time as the while loop is still running?
This is my current while loop:
while truth==true
writeline(Pgauge,"0010074002=?106"); % Sends a telegram to the gauge that asks for the current pressure
livedata=readline(Pgauge); % Reads gauge's response
sigdig=extractBetween(livedata,11,14); %incoming message is messy, sigdig and exponent take the numbers
exponent=extractBetween(livedata,15,16); %important to the reading
Pread=str2double(sigdig)/1000*10^(str2double(exponent)-20); %Makes a legible reading
addpoints(liveline,time,Pread); % adding points to animate line (liveline)
drawnow limitrate
temp=[Pread,time]; %creating a backup
backup=[backup;temp]; %I know this is terribly inefficient any recommendations for this would also be nice
dlmwrite(filename,temp,'delimiter',',','-append'); %saving data to csv file
pause(interval); %pause between loops
time=time+interval; %tracks time
end
0 Commenti
Risposte (1)
Milan Bansal
il 1 Apr 2024
Hi Seiji Oishi,
To address your concern about visualizing the data effectively due to the wide range of pressure values, you can use a dynamic y-axis range or a logarithmic scale for the y-axis. A separate plot frozen in time while the main loop continues to run can be a bit more complex.
Dynamic Y-Axis Range : Adjust the y-axis limits based on the most recent pressure readings. Set the limits to a range that covers the last few readings within a certain factor of the current pressure. This approach keeps the plot zoomed in around the current value.
% Inside the loop, after adding points
drawnow limitrate;
ylim([min(Pread*0.5, lowerBound), max(Pread*1.5, upperBound)]); % Adjust as needed
Logarithmic Scale : Using a logarithmic scale for the y-axis can help accommodate a wide range of values more comfortably. This is especially useful for pressure readings that span several orders of magnitude.
% Set the y-axis to logarithmic scale
set(gca, 'YScale', 'log');
% Make sure to set this before the loop starts
Please refer to the following documentation links to learn more about "ylim" and "set" functions.
Hope this helps!
0 Commenti
Vedere anche
Categorie
Scopri di più su Graphics Performance in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!