To label same X axis twice

2 ビュー (過去 30 日間)
seema niran
seema niran 2018 年 4 月 11 日
コメント済み: Pawel Jastrzebski 2018 年 4 月 12 日
Sir, I have hourly data to plot. My plot show the days in X axis as shown below. Is there any method to divide each day to show 24 hours too.

回答 (1 件)

Pawel Jastrzebski
Pawel Jastrzebski 2018 年 4 月 11 日
You can certainly add minor ticks and show them on the grid but I'm not sure if there's an easy way to label them. In other words, you'll get the tick and the grid lines but not the 1 through 24 labels.
See example below:
% RANDOM DATA - 2 days x 24hrs
StartDate = datetime(2018,1,1,0,0,0);
EndDate = datetime(2018,1,2,23,0,0);
NoOfHours = hours(EndDate-StartDate)+1;
xTimeSpan = StartDate:hours(1):EndDate;
y = rand(1,NoOfHours).*randi([10,50],1,NoOfHours);
f(1) = figure;
ax(1) = gca();
p(1) = plot(xTimeSpan,y,'.k');
grid on
% Grid settings
set(ax(1),...
'XMinorTick','on',...
'XMinorGrid','on',...
'MinorGridColor',[0 1 0],...
'MinorGridAlpha',0.15,...
'MinorGridLineStyle','-');
% x-grid values
set(ax(1).XAxis,...
'TickValues' ,StartDate:EndDate,...
'MinorTickValues',xTimeSpan);
The output:
  2 件のコメント
seema niran
seema niran 2018 年 4 月 12 日
Sir, it is ok. but what I need is a separate labeling of 0 to 23 for each day section either along or at the top of the x-axis. Thank you
Pawel Jastrzebski
Pawel Jastrzebski 2018 年 4 月 12 日
I'm afraid that off-the-box Matlab doesn't offer a capability to add labels to the minor ticks.
Potential workaround would be to use the:
To add the minor ticks to the plot, but you will have to specify the (x,y) coordinates for every label.
Or alternatively, present your data in a different orientation by swapping the x-axis with the y-axis. Then you could use Matlab's:

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

カテゴリ

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