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

15 次查看(过去 30 天)
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

采纳的回答

Steven Lord
Steven Lord 2023-2-16
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 个评论
patrice boisset
patrice boisset 2023-2-17
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by