How can I modify the datetime ticks used in heatmaps

조회 수: 4 (최근 30일)
Gayan Lankeshwara
Gayan Lankeshwara 2020년 8월 21일
댓글: Gayan Lankeshwara 2020년 8월 28일
I am using datetime ticks to represent the x-axis as given in the following MWE code.
%% random heatmap
h1 = heatmap(rand(60))
%% generating the array for the x axis
tstart = datetime(2020,08,21,15,01,0);
tend = datetime(2020,08,21,16,00,0);
x_time = tstart: minutes(1): tend
x_time.Format = 'HH:mm'
%% changing the x ticks to be the time
h1.XDisplayLabels = x_time ;
Instead of displaying all the xtick labels, how can I only show the xtick labels every 10 mins, something similar to this {15:10, 15:20, ...}.
I tried this, but using mode function is impossible with datetime date I guess.
In addition to that, I want to change the ticks in the colorbar of the heatmap to be something like 'foo 0.1' instead of 0.1.
Could you please help me to sort this out ?
Thank you.

채택된 답변

Jyotsna Talluri
Jyotsna Talluri 2020년 8월 25일
The below code helps
CustomXLabels = string(x_time);
% Replace all but the tenth elements by spaces
CustomXLabels(mod(minute(x_time),10) ~= 0) = " ";
% Set the 'XDisplayLabels' property of the heatmap object 'h1' to the custom x-axis tick labels
h1.XDisplayLabels = CustomXLabels;
axs = struct(gca);
cb = axs.Colorbar;
cb.TickLabels = {'foo 0.1','foo 0.2','...'};

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by