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

3 views (last 30 days)
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?

Accepted Answer

Amy
Amy on 21 Dec 2017
Edited: Amy on 21 Dec 2017
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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!