Plotting date-times with date in top right corner instead of bottom right
3 views (last 30 days)
Show older comments
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?
2 Comments
Jan
on 18 Dec 2017
Maybe it would be useful, if you mention which "in the MATLAB help page" you mean.
Accepted Answer
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.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!