Plot time series in selected axes

4 views (last 30 days)
PaoloB
PaoloB on 12 Mar 2015
Commented: Star Strider on 12 Mar 2015
How can I plot a time series in an axes, for which I know the handle, rather than in the currently active axes?
For standard plots, if myTargetAxes is the handle to the axes, I can do:
plot(myTargetAxes, 1:200, tan((1:200)./12));
But this does not work with a time series because I can do
plot (myTimeseries)
but if I attempt to do
plot(myTargetAxes, myTimeseries)
I get the error: "A numeric or double convertible argument is expected."
I have found the workaround of calling
axes(myTargetAxes)
before
plot(myTimeseries)
but this seems very ugly. Is there a better way to do it?

Accepted Answer

Guillaume
Guillaume on 12 Mar 2015
plot for timeseries is actually a different function than the general plot. It's a member function of the timeseries class.
I just went through the code of the plot function ( edit timeseries.plot), and the way to specify the axes is with:
plot(myTimeseries, 'Parent', myTargetAxes);
It's kind of alluded to in the documentation where it says that Name, Value is used to specify the Chart Line properties. One of the chart line properties is indeed the parent axis. It certainly could be a bit more explicit.
  2 Comments
PaoloB
PaoloB on 12 Mar 2015
Hi Guillaume, thank you very much, it worked.
Star Strider
Star Strider on 12 Mar 2015
Great work, Guillaume!
+1

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!