yyaxis: avoid overlapping time series
5 views (last 30 days)
Show older comments
Hi Community,
My problem: I want to plot two time series (one containing actual data, the other containing model predictions - so nothing fancy here). To be able to compare both time series visually, I would like to plot them together using yyaxis. When I do so, however, of course Matlab adjusts the axis automatically (which is by itself a good feature). Unfortunately, this leads the two time series to overlap partially, since they are very volatile. I would thus like to offset the y-axis slightly, such that the corresponding time series do not overlap anymore. I have searched the internet for a solution and was very surprised that nobody seems to have had the problem. Attached you will find some plots (obtained from google pictures)for you to get the idea.
This is something I have (you see the timeseries overlapping):

This is something I would like to have (you see that the time series are offset slightly and don't overlap):

My minimum working example (so nothing fancy):
figure
yyaxis left
plot(x,y)
datetick('x','yyyy')
yyaxis right
plot(x,z)
datetick('x','yyyy')
My suspicion is that I have to adjust the y-axis limits manually. Since I have to wrap a function around the whole thing (I compute different models I want to plot likewise), the whole thing needs to be flexible. I am not sure, however, how that would be achieved.
I hope my the above makes my issue clear. I you have any follow-ups please do not hesitate to ask. Any help is greatly appreciated.
Looking forward to all the great suggestions
Kind regards
0 Comments
Answers (1)
Ameer Hamza
on 2 May 2018
Use ylim() to change the y axis limits. It will appear as an offset to the second plot. As an example
yyaxis right
plot(x,z)
ylim([-500, 1500])
datetick('x','yyyy')
3 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!