Exclude certain dates on x-axis using xlim or xtick?

4 ビュー (過去 30 日間)
Louise Wilson
Louise Wilson 2021 年 10 月 22 日
コメント済み: Louise Wilson 2021 年 10 月 22 日
I have attached my dataset and a plot to illustrate what I am trying to do. I would like to remove the blank spaces between the data to account for the fact that no data was collected between 5pm-8am. It would be useful to mark the boundary of each new day with a vertical line. Is there a way to do this?
% Create datasets for plotting (from y.mat)
backg = y(:,2);
backg(y(:,4)~=0) = NaN;
inter = y(:,2);
inter(y(:,4)<1) = NaN;
y_dt=datetime(y(:,1),'ConvertFrom','datenum');
% Plot
figure(1)
bar(y_dt,backg,'g')
hold on
bar(y_dt,inter,'r')
plot(y_dt,y(:,3),'black'); %plot threshold
xlim([datetime(2020,2,5,08,0,0), datetime(2020,2,7,17,0,0)]); %filter to date range of interest
  2 件のコメント
dpb
dpb 2021 年 10 月 22 日
Not with the real datetime on the x-axis, no.
There are ways to work around the problem by plotting against ordinal values (which won't work if the time points aren't uniform) or by using datenum time-of-day and an arbitrary date and then fix up the tick labels manually.
All in all, it's a royal p(ain)it(proverbial)a(ppendage).
Louise Wilson
Louise Wilson 2021 年 10 月 22 日
Haha. Typical because in my last question about plotting (https://au.mathworks.com/matlabcentral/answers/1568318-discrepancy-between-datenum-and-datetime?s_tid=srchtitle) I was advised to always use datetime haha... jeez. Maybe I will try photoshop...

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

採用された回答

the cyclist
the cyclist 2021 年 10 月 22 日
One possible solution to this would be to use a tiledlayout to plot each day in its own subplot.
  3 件のコメント
the cyclist
the cyclist 2021 年 10 月 22 日
OK. FYI in case you don't know, you can make a tiled layout with no spacing between tiles, so it seems guaranteed to take less space (at least effectively) than what you posted here.
Louise Wilson
Louise Wilson 2021 年 10 月 22 日
Nice, I will try that, thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by