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

15 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Steven Lord
Steven Lord am 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 Kommentar
patrice boisset
patrice boisset am 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Exploration finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by