change x axis in a plot

2 views (last 30 days)
sarah sh
sarah sh on 12 Aug 2015
Answered: dpb on 12 Aug 2015
Hello everyone,
I would like to plot a graph vs the month names ('Jan' 'Feb' ... 'Dec'). I have in fact the solar power generation for a year in a vector (length = 5525600) and I tried with this:
h=plot(solar)
set(get(h,'Parent'),'XTickLabel',{'Jan' 'Feb' 'Mar' 'Apr''May' 'Jun' 'Jul' 'Aug' 'Sept' 'Oct' 'Nov' 'Dec'})
The problem is that all the months are not shown below the x axis. It stops at 'Jul'. Can someone help me with this please?
Thank you

Answers (1)

dpb
dpb on 12 Aug 2015
Convert the times to date numbers and plot against them (or compute from the sampling time the locations in the vector that are the beginning of month indices).
If use the former, then use datetick to format the axes labels as times and set the tick marks to the first day of the month (using the date number).
The reason the labels written above stopped at July is that there were seven tick marks by default; you have to set the number of ticks to the number that you want labels for and at those values, either in date numbers if use it or as indices into a linear array if that's the way you plot.

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!