Bozmaje
Bozmaje

Reputation: 75

How to change xticks interval in all my subplots?

I using this code in order to have 6 plots in one figure. I want to change the interval of the x-axis for all subplots to 5 years by 5 years. like 1990, 1995, 2000, 2005, ... in fact, I want blank space between them in order to increase readability. Also, I want the smallish font size of this x thick. Here is my figure: enter image description here

and here is my code:

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;

I want to ask you please help me on this issue.

Upvotes: 0

Views: 222

Answers (1)

user1543042
user1543042

Reputation: 3442

Give this a try

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

Upvotes: 2

Related Questions