How do I specify an axes when plotting timeseries data?

3 次查看(过去 30 天)
I cannot use the plot function on timeseries data with an axis handle as the first input. I use timeseries data a lot and use the plot command with it. However, I cannot plot a timeseries directly to a particular axis unless I manually specify the time and data vector. See below code:
>> x = timeseries([10;15;18;28],[0; 1; 2; 3])
>> figure
>> h1 = gca
>> plot(h1,x) % does not work
>> plot(h1,x.Time,x.Data) % this does work. This is not ideal

采纳的回答

MathWorks Support Team
The "plot" function invokes different methods of plotting depending on the input data provided. Since this is timeseries data, the syntax for plotting the timeseries to a particular axis in this example would look like the following:
>> plot(x, 'Parent', h1)
This is because the timeseries plotting function uses the syntax:
plot(ts,specs)
where "specs" refers to the Line Specifications as a 'Name', 'Value' pair. This is not entirely obvious since the "plot" documentation specifies axes as the first input. More information on this syntax may be found at the documentation link below:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by