How to keep ticks on xaxis without the xlabels disappearing automatically

조회 수: 10 (최근 30일)
I am trying to plot 3 x 2 plots in a single window so that only the plots in 3rd row have xaxis ticks and labels. My xaxis has 219 points and I need the xticks to be closely spaced. When I write the command for xticks, the xlabels disappear. Please help. Also I need the xaxis label to be formatted in two lines. The months as ticks and the second line as year. Any help in that regard would be appreciated. Below is my sample code.
Qnet=ncread('extracted_netflux_088.nc', 'NETFLUX');
Qpen1=ncread('Qpen_088_change.nc', 'QPEN');
ax6 = axes('Position',[0.54 0.07 0.4 0.29]);
plot(X(1,1:219),squeeze(Qnet),'k','LineWidth',1.2);xlim([t(1) t(end)]);
ylabel('Netflux');
yyaxis right;
plot(X(1,1:219),squeeze(Qpen1),'b','LineWidth',1.2);
ylabel('Qpen','FontSize',12,'FontWeight','bold','Color','b');
xtck=1:55:219;
set(gca,'YColor',[0 0 1]);
set(gca, 'XTickLabel',datestr(t(1:55:219),('mmm-yy')),'FontWeight','bold','FontSize',8);
set(gca,'XTick', xtck);

채택된 답변

Walter Roberson
Walter Roberson 2020년 3월 20일
When you set XTick, MATLAB automatically resets XTickLabel, but the opposite is not true. So set XTick first and then set XTickLabel .
  댓글 수: 11
Trishneeta Bhattacharya
Trishneeta Bhattacharya 2020년 3월 23일
This worked. Thank you so much. Can you edit your answer in the first part so that I can accept it.
Walter Roberson
Walter Roberson 2020년 3월 25일
Accepting accepts the entire Answer thread. It is common that the first response turns out not to solve the problem, as problems are often more complex than users write about at first.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by