フィルターのクリア

Modify axis tick frequency

45 ビュー (過去 30 日間)
Christoph Meier
Christoph Meier 2015 年 8 月 12 日
コメント済み: Ehsan Modiri 2020 年 6 月 27 日
Dear Matlab community,
I have successfully produced the following plot:
by using the following code:
dn=datenum(1926,7+[0:(2014-1926)*12+5].',1);
datestr([dn(1),dn(end)]);
plot(dn,y);
xlim([dn(1) dn(end)]);
datetick('x','mm/yyyy','keeplimits');
I now would like to adjust the frequency of the x-axis date ticks, but I cannot make sense of the function. I believe datetick is set on auto mode, where it produces a default number of ticks. I am looking for 1-year and 5-year intervals.
Thank you very much! The help from the MATLAB community has helped me a great deal!
Chris

採用された回答

Walter Roberson
Walter Roberson 2015 年 8 月 12 日
If you want 1 year and 5 year ticks both at the same time then you would be wanting the 1 year ticks to be Minor Ticks and the 5 year ticks to be the major ticks. See http://www.mathworks.com/matlabcentral/answers/97759-how-do-i-add-minor-ticks-to-a-graph for information about setting minor ticks.
For the 5 year ticks:
tick5 = datenum(1930:5:2014,1,1);
set(gca, 'xtick', tick5);
datetick('x', 'yyyy', 'keepticks');
  2 件のコメント
Christoph Meier
Christoph Meier 2015 年 8 月 12 日
Thank you very much!
Ehsan Modiri
Ehsan Modiri 2020 年 6 月 27 日
tick5 = datetime(1930:2014,1,1);
set(gca, 'Xtick', tick5)
instead of datenum, you can use datetime.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by