set number of ticks at any given time

9 次查看(过去 30 天)
i am searching for something to set the amunt of ticks to a fix value of a plot.
the reason is, right now im plotting live data and the plot constantly changes the number of ticks and therefore the space inbetween, wich makes it harder to read than necessary.
now i know that i can change XTick to values of my liking, but when i do, i also have to change them all the time in the loop, so my tought was to simply change the amount of xticks. however, i couldnt find a solution. i am using animatedline, does that make a difference?


Steven Lord
Steven Lord 2023-6-20
If you know the bounds over which your data to be plotted spans, I would set those limits first using axis or xlim and ylim (and set the ticks and tick labels with xticks, xticklabels, etc.) then addpoints to your animatedline. Doing so means that the axes will not need to recalculate its limits to include the new points and so the ticks won't need to change during the plotting.
Run the following two sections of code and watch the plotting. The first doesn't need to change the limits at all once the axes is created by the axis call. The second updates the limits with each new point. [The effect in MATLAB Answers is the same, since it only shows the final results, but in an interactive MATLAB session you will be able to see the difference.]
With axes limits set initially:
x = 0:10;
y = x.^2;
[minX, maxX] = bounds(x);
[minY, maxY] = bounds(y);
axis([minX maxX minY maxY])
h = animatedline(NaN, NaN);
for k = 1:numel(x)
addpoints(h, x(k), y(k));
Without axes limits set initially:
h = animatedline(NaN, NaN);
for k = 1:numel(x)
addpoints(h, x(k), y(k));
  4 个评论
Andre 2023-6-21
im a little lost right, i made a new script where i can test it out, so i dont have to screw around in the script i am using at the end. after i did it, i let it run and i do not have the same effect, it is working there as i want it to work.
so im not sure whats causing it.


更多回答(1 个)

Richard Burnside
Richard Burnside 2023-6-20
The "xticks" and "yticks" command will let you manually set your tick values.
  1 个评论
Andre 2023-6-20
编辑:Andre 2023-6-20
but thats exactly what i dont want to do. my goal is to have it always have 10 ticks, and not some auto-stuff interfere and change it with each loop iteration, but i cant find such a thing.
and thanks :)



Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息




Community Treasure Hunt

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

Start Hunting!

Translated by