how to refrech XticksLabel when i zoom a graph in an app

15 views (last 30 days)
Good morning
I'm using datestr for printing time on th xlabel axis but if i zoom all the label became wrong.
I've got the write command to refresh the X labels but I think there is a mean to create a callback when the zoom is activated.
I'm in a app designed figure but if it's possible in classicle figure i'm intersted to.
regards

Accepted Answer

Steven Lord
Steven Lord on 16 Feb 2023
Rather than calling datestr or datetick I recommend plotting using a datetime array as your X data.
v = 0:10;
y = v.^2;
tenDays = datetime('today') + days(v)
tenDays = 1×11 datetime array
16-Feb-2023 17-Feb-2023 18-Feb-2023 19-Feb-2023 20-Feb-2023 21-Feb-2023 22-Feb-2023 23-Feb-2023 24-Feb-2023 25-Feb-2023 26-Feb-2023
plot(tenDays, y)
As you zoom in on the axes MATLAB will automatically update the tick labels. If you want to customize the format used to display the datetime data you can use the xtickformat function to do so.
  1 Comment
patrice boisset
patrice boisset on 17 Feb 2023
Hello Steven
Thank you for the answer. This solution is very convinient while there is only one plot in the same axis but in my case there is different lines with diferents time vector and in that case the zoom made strong Xscale because of the Xlabels that don't folow.
Below the second graph has been zoomed between 12 and 13 o'clock and the plot has been done with datetime solution.
So I went back to my old manner and i'm steel interested for the way to code a callback after a zoom in an app and or a figure.
Thanks

Sign in to comment.

More Answers (0)

Categories

Find more on Data Exploration in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!