Main Content

このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。

plot

timeseries のプロット

説明

plot(ts) は、tstimeseries データを時間に対してプロットし、サンプル間の値を内挿します。

plot(ts,LineSpec) は、線グラフを使用して timeseries データをプロットし、指定した specs をラインまたはマーカー、あるいはその両方に適用します。

また、名前と値の引数を指定して Line のプロパティ を定義することもできます。

すべて折りたたむ

時系列オブジェクトを作成し、開始日を設定して、開始日に相対的に時間ベクトルをプロットします。

x = [2 5 8 2 11 3 6];
ts1 = timeseries(x,1:7);

ts1.Name = 'Daily Count';
ts1.TimeInfo.Units = 'days';
ts1.TimeInfo.StartDate = '01-Jan-2011';     % Set start date.
ts1.TimeInfo.Format = 'mmm dd, yy';       % Set format for display on x-axis.

ts1.Time = ts1.Time - ts1.Time(1);        % Express time relative to the start date.

plot(ts1)

Figure contains an axes object. The axes object with title Time Series Plot:Daily Count contains an object of type line.

交通量の調査データから 2 つの時系列オブジェクトを作成し、同じ座標軸上に順番にプロットします。イベントを系列に追加すると、自動的に赤色のマーカーで表示されます。

load count.dat;
count1 = timeseries(count(:,1),1:24);
count1.Name = 'Oak St. Traffic Count';
count1.TimeInfo.Units = 'hours';
plot(count1,':b')
grid on

Figure contains an axes object. The axes object with title Time Series Plot:Oak St. Traffic Count contains an object of type line.

最大値の時間を取得してイベントとして追加します。

[~,index] = max(count1.Data);
max_event = tsdata.event('peak',count1.Time(index));
max_event.Units = 'hours';

このイベントを時系列に追加します。

count1 = addevent(count1,max_event);

イベントを表示する新しいプロットに、プロットを置き換えます。

plot(count1,'.-b')
grid on

Figure contains an axes object. The axes object with title Time Series Plot:Oak St. Traffic Count contains 2 objects of type line.

同じデータ ソースの列 2 から新しい時系列オブジェクトを作成します。

count2 = timeseries(count(:,2),1:24);
count2.Name = 'Maple St. Traffic Count';
count2.TimeInfo.Units = 'Hours';

ホールドをオンにして新しいデータをプロットに追加します。

hold on

このプロット メソッドはホールドされたプロットにラベルは追加しません。プロパティと値のペアを使用してマーカーをカスタマイズします。

plot(count2,'s-m','MarkerSize',6),

Figure contains an axes object. The axes object with title Time Series Plot:Oak St. Traffic Count contains 3 objects of type line.

ラベルは消去されているため、手動でラベルを生成します。

title('Time Series: Oak Street and Maple Street')
xlabel('Hour of day')
ylabel('Vehicle count')

左上に凡例を追加します。

legend('Oak St.','Maple St.','Location','northwest')

Figure contains an axes object. The axes object with title Time Series: Oak Street and Maple Street contains 3 objects of type line. These objects represent Oak St., Maple St..

入力引数

すべて折りたたむ

入力 timeseries。スカラーとして指定します。

ライン スタイル、マーカーおよび色。記号を含む string または文字ベクトルとして指定します。記号の順番は任意です。3 つの特性 (ライン スタイル、マーカーおよび色) をすべて指定する必要はありません。たとえば、ライン スタイルを省略してマーカーを指定する場合、プロットはラインなしでマーカーのみを表示します。

例: "--or" は円形マーカー付きの赤い破線

ライン スタイル説明結果として得られる線
"-"実線

Sample of solid line

"--"破線

Sample of dashed line

":"点線

Sample of dotted line

"-."一点鎖線

Sample of dash-dotted line, with alternating dashes and dots

マーカー説明結果のマーカー
"o"

Sample of circle marker

"+"プラス記号

Sample of plus sign marker

"*"アスタリスク

Sample of asterisk marker

"."

Sample of point marker

"x"十字

Sample of cross marker

"_"水平線

Sample of horizontal line marker

"|"垂直線

Sample of vertical line marker

"square"正方形

Sample of square marker

"diamond"菱形

Sample of diamond line marker

"^"上向き三角形

Sample of upward-pointing triangle marker

"v"下向き三角形

Sample of downward-pointing triangle marker

">"右向き三角形

Sample of right-pointing triangle marker

"<"左向き三角形

Sample of left-pointing triangle marker

"pentagram"星形五角形

Sample of pentagram marker

"hexagram"星形六角形

Sample of hexagram marker

色名省略名RGB 3 成分外観
"red""r"[1 0 0]

Sample of the color red

"green""g"[0 1 0]

Sample of the color green

"blue""b"[0 0 1]

Sample of the color blue

"cyan" "c"[0 1 1]

Sample of the color cyan

"magenta""m"[1 0 1]

Sample of the color magenta

"yellow""y"[1 1 0]

Sample of the color yellow

"black""k"[0 0 0]

Sample of the color black

"white""w"[1 1 1]

Sample of the color white

ヒント

  • 関数 plot は、タイトルと軸のラベルを自動的に生成します。生成されるラベルは次のとおりです。

    • プロットのタイトル — 'Time Series Plot: <name>'

      ここで、<name> は、ts.Name に割り当てられた文字列、または既定の設定で 'unnamed' です。

    • X 軸ラベル — 'Time (<units>)'

      ここで、<units> は、ts.TimeInfo.Units フィールドの値 (既定は 'seconds') です。

    • Y 軸ラベル — '<name>'

      ここで、<name> は、ts.Name に割り当てられた文字列、または既定の設定で 'unnamed' です。

  • 新しい時系列データは時系列プロットに配置できます (たとえば、hold on を設定して、別の timeseries/plot コマンドを実行します)。データをプロットに追加すると、ラベル作成時の混乱を避けるために、タイトルと座標軸ラベルが空白文字列になります。プロット後に独自のラベルを追加するには、title コマンド、xlabel コマンド、および ylabel コマンドを使用します。

  • 時系列イベントが定義されている場合、赤色で塗りつぶされた円のマーカーを使用してプロットに印をつけます。データで定義されているイベント マーカー以外に、関数 linespec または名前と値の構文も使用すれば、すべてのデータ点のマーカーを指定できます。イベント マーカーは定義したマーカーの一番上にプロットされます。

  • ts.DataInfo.Interpolation.Name に割り当てられた値は、時系列データのプロットおよびリサンプリング時に plot メソッドで使用する内挿の種類を制御します。既定の線形内挿をゼロ次ホールド内挿 (階段型) に変更するには、timeseries メソッド setinterpmethod を呼び出します。このメソッドによって新しい timeseries オブジェクトが作成され、必要に応じて元のオブジェクトを上書きできます。たとえば、時系列 ts がゼロ次ホールド内挿を使用するようにするには、以下のように入力します。

    ts = ts.setinterpmethod('zoh');

バージョン履歴

R2006a より前に導入