Help with labelling the axes of a plot.

1 view (last 30 days)
I have a simple plot of data measured once a month over 4 years. My code looks like this:
t=1:1:48
ydata=[48 different values]
plot(t,ydata)
I'm still very much a novice with MATLAB, & while I know to add a label to the x-axis, what I would like to do with this plot on the x-axis, is split it into sections of 12 numbers to clearly show the results of each year on the plot. So that there would be one seperate section for t=1:12, and another for t=13:24, etc. Any help with this would be much appreciated, thank you very much.
  2 Comments
Walter Roberson
Walter Roberson on 18 Mar 2019
Do you want to create two separate plots? If not then how would you like to mark the two different sections?
Connor Marvell
Connor Marvell on 18 Mar 2019
My apologies, I wasn't clear. I'd like just one plot, but I'd like each 12 values on the x-axis to be highlighted differently somehow, just to show clearly that they are representing different years.

Sign in to comment.

Accepted Answer

dpb
dpb on 18 Mar 2019
Edited: dpb on 18 Mar 2019
Something like
hL=plot(reshape(t,12,[]),reshape(y,12,[]));
is really easy to get the effect by ML's treating each column on an array as a separate variable. The one thing might not care for w/o some fixup is this leaves a break between the line segments...so, another way would be
plot(t,y,'k-') % draw solid line first
hold on
hL=plot(reshape(t,12,[]),reshape(y,12,[]),'*-'); % then add colored markers
untitled.jpg
Add legends to label color, change symbols, etc., to "salt to suit!"...
  1 Comment
Connor Marvell
Connor Marvell on 18 Mar 2019
This is perfect thank you, exactly what I was after. Thanks a lot for this!

Sign in to comment.

More Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!