首页 > 解决方案 > 如何更改我所有子图中的 xticks 间隔?

问题描述

我使用此代码是为了在一个图中有 6 个图。我想将所有子图的 x 轴间隔更改为 5 年 5 年。像 1990, 1995, 2000, 2005, ...事实上,我希望它们之间有空格以增加可读性。另外,我想要这个 x 厚的小字体。这是我的图: 在此处输入图像描述

这是我的代码:

plotMonths=[1,3,6,12,24,48].';           % list of month intervals desired for plot
plotColors=['r';'b';'k';'g';'m';'c'];    % colors; use whatever desired or rgb triplet
figure;
for i=1:6
  hAx(i)=subplot(2,3,i);          % create subplot, save axes handle
  hL(i)=plot(Date,SPI_table.("SPI_"+plotMonths(i)+"month"),plotColors(i),'linewidth',1); 
  xlabel('time step')
  ylabel("SPI "+plotMonths(i)+"month")
  xticks(Date(1:12:end))
  set(hAx(i),'XTickLabelRotation',90)
end

subplot(2,3,1)
title('SPI 1')
subplot(2,3,2)
title('SPI 3')
subplot(2,3,3)
title('SPI 6')
subplot(2,3,4)
title('SPI 12')
subplot(2,3,5)
title('SPI 24')
subplot(2,3,6)
title('SPI 48')
sgt = sgtitle('Nonparametric SPI for Abadan Station','Color','red');
sgt.FontSize = 20;

我想请你帮我解决这个问题。

标签: matlab

解决方案


试试这个

xticks( datetime( 1995:5:2020 , 1 , 1 ) )

推荐阅读