how do i use datetime adjust xtick

조회 수: 11 (최근 30일)
peter huang
peter huang 2022년 9월 26일
댓글: Eric Sofen 2022년 9월 26일
when i useing datetime plot timeseries
i want adjust year by year xtick
ex. 2007 2008 2009 2010 2011 ... 2022
Is there any way to adjust xtick besides using datetick\
clear all ; clc ; clf
load data_1206_wl_max.mat
all_time_1206 = datetime(all_time_outliner_1206 ,'ConvertFrom','datenum'); %% x
plot( all_time_1206 , all_tide_outliner_1206,'k' );hold on
% datetick('x','yyyy')
this pictuer not using datetick
xtick is 2008 2010 2012 2014 ... 2020
i want get to know if datetime can adjust xtick more freely
  댓글 수: 1
Chunru
Chunru 2022년 9월 26일
datatick has a lot of options for changing the format of the xticks such as below. What additional customization doy you want?
datetick('x', 'mm/yyyy')

댓글을 달려면 로그인하십시오.

채택된 답변

RAGHUNATHRAJU DASHARATHA
RAGHUNATHRAJU DASHARATHA 2022년 9월 26일
As per my understanding you want to know how to adjust xticks in datetime plot
I will try to explain it using an example below
startDate = datenum('01-01-2009');
endDate = datenum('12-31-2009');
xData = linspace(startDate,endDate,12)
xData = 1×12
1.0e+05 * 7.3377 7.3381 7.3384 7.3387 7.3391 7.3394 7.3397 7.3401 7.3404 7.3407 7.3410 7.3414
yData=rand(1,12)
yData = 1×12
0.8718 0.0657 0.8671 0.3537 0.9655 0.9012 0.9318 0.3869 0.1760 0.7679 0.0407 0.4823
plot(xData,yData)
ax = gca;
ax.XTick = xData;
For any further information you can go through the link

추가 답변 (1개)

Simon Chan
Simon Chan 2022년 9월 26일
Try the following without using the function datetick.
f = figure;
ax=gca;
plot(ax,all_time_1206 , all_tide_outliner_1206,'k' );
ax.XLim(2) = datetime(2022,1,1); % Set the limit to 1 Jan 2022
ax.XTick = ax.XLim(1):calyears(1):ax.XLim(2); % Modify XTick based on the limits
  댓글 수: 1
Eric Sofen
Eric Sofen 2022년 9월 26일
I'd encourage you to follow @Simon Chan's advice to use datetime rather than datenum and datetick. With the recent R2022b release, datenum is not recommended.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by