How to plot a time series with multiple y axes

3 views (last 30 days)
Julian
Julian on 28 Jan 2016
Commented: Julian on 2 Feb 2016
Hi!
I would like to plot 3 data sets with different scales over the same time axis. It would look like the image below that was created with a different software. There use see the time on the x-axis, and 3 different y-axes for my pressure, depth and temperature data.
My data is stored in 3 time series:
ts_p = timeseries(p_hydro, time, 'Name', 'Pressure');
ts_T = timeseries(T, time, 'Name', 'Temperature');
ts_sensorDepth = timeseries(sensorDepth, time, 'Name', 'Sensor Depth');
I tried the function plotyyy that I found on File Exchange http://www.mathworks.com/matlabcentral/fileexchange/1017-plotyyy
plotyyy(ts_p.Time, ts_p.Data, ts_T.Time, ts_T.Data, ts_sensorDepth.Time, ts_sensorDepth.Data, {'kPa', 'degC', 'meters'})
But the properties of the x-axis where not the same as those of a simple time series plot, e.g.
plot(ts_p)
In this case, the x-axis can be formated to show a certain time format, e.g.'mm/dd/yy HH:MM:SS', and when you zoom in, the x-axis adjust itself. I would like to have these features in my plot.
Does anybody have an idea?

Answers (1)

Walter Roberson
Walter Roberson on 29 Jan 2016
ax3 = plotyyy(ts_p.Time, ts_p.Data, ts_T.Time, ts_T.Data, ts_sensorDepth.Time, ts_sensorDepth.Data, {'kPa', 'degC', 'meters'});
for ax = ax3(:).'
datetickzoom(ax, 'MM/DD/YY');
end
linkaxes(ax3, 'x');
  1 Comment
Julian
Julian on 2 Feb 2016
Thanks! That almost did the job, but not quiet. The x-axis is a bit chaotic as you can see in the screenshot. My time data run from June 23. to Dec. 8. and all time vectors are equal, i.e.
ts_p.Time = ts_T.Time = ts_sensorDepth.Time

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!