how to set a frequency of x axis of a plot?

29 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2020 年 7 月 5 日
編集済み: dpb 2020 年 7 月 5 日
I have a plot
plot(yyyyMM,temperature)
This plot has x axis that shows year. But I want to have more fine ticks such as quaterly, monthly, etc. How can one set such frequency?
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 7 月 5 日
Can you show us some pictorial representation?
alpedhuez
alpedhuez 2020 年 7 月 5 日
編集済み: alpedhuez 2020 年 7 月 5 日

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

採用された回答

dpb
dpb 2020 年 7 月 5 日
If your variable is (as was suggested in other thread asking about formatting it) a datetime, just use xticks with the time span you want (as datetimes/durations).

その他の回答 (1 件)

dpb
dpb 2020 年 7 月 5 日
編集済み: dpb 2020 年 7 月 5 日
Read up on datetime and plot and the DatetimeRuler...
t=datetime(2018:2033,1,1); y=randn(size(t)); % dummy data over your time frame
plot(t,y)
xl=xlim; % get the axis limits array
xt=xl(1)+calmonths(0:6:(2032-2018+1)*6*2); % compute ticks on 6 calendar month cycle
xticks(xt) % and set on graph
hAx=gca; % get axes handle
hAx.XAxis.TickLabelRotation=45; % rotate the labels 45 degrees
Above yields
As you'll observe, date tick labels take up a lot of room; you'll have to stretch out the axis, make the font smaller, shorten the format chosen or just use fewer of 'em, but that's the basics.
It's no problem if use the right data class.
hAx.XAxis.TickLabelInterpreter='none';
hAx.XAxis.TickLabelFormat='yyyy_MM';
will set the format string to display the yyyy_MM string which is a little less verbose -- the underscore gets interpreted as subscript for subsequent character w/ default 'TeX' interpreter; hence the 'none'

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by