Plotting date-times with date in top right corner instead of bottom right

조회 수: 3 (최근 30일)
Jonathan VO
Jonathan VO 2017년 12월 18일
편집: Amy 2017년 12월 21일
When I plot some data against date-time values, the x-axis ticks contain only the times, and the bottom right hand corner contains the date. For example, in the MATLAB help page for plotting dates and durations, the very bottom plot the x-axis ticks are the months, and the bottom right hand corner shows the year. Is there a way to move the value at the bottom right hand corner to the top right hand corner, above the figure?

채택된 답변

Amy
Amy 2017년 12월 21일
편집: Amy 2017년 12월 21일
Hi Jonathan, there's this MATLAB answers post that you could refer to if you wanted to change the format of the x axis labels.
I'm not sure if there's a way to move just the secondary label to the top of the figure, but if you want to move all the x-axis labels to the top, after plotting your data, you could use the following commands:
ax = gca; ax.XAxisLocation = 'top';
If you're just moving that label from the bottom right corner to the top right corner, and you know nothing else in your figure is going to change, as a workaround you could do this: reassign the x tick labels, because this will hide the secondary label that automatically shows up. Then manually add a text box in the top right hand corner (or wherever you want it) by clicking on "Insert -> TextBox" in the figure window.
This command will hide the secondary x axis label:
xticklabels manual;
Note that this has a limitation that when you zoom or pan the plot, the tick labels will not update automatically.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by