Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

ライン プロットとステム プロットの組み合わせ

この例では、1 つのライン プロットと 2 つのステム プロットを組み合わせる方法を説明します。その後、タイトル、軸ラベルおよび凡例を追加する方法を説明します。

データを作成し、ラインをプロットします。

x = linspace(0,2*pi,60);
a = sin(x);
b = cos(x);
plot(x,a+b)

Figure contains an axes object. The axes object contains an object of type line.

2 つのステム プロットを座標軸に追加します。hold on を使用して、既存のプロットが新しいプロットに置き換えられないようにします。

hold on
stem(x,a)
stem(x,b)
hold off

Figure contains an axes object. The axes object contains 3 objects of type line, stem.

タイトル、軸ラベルおよび凡例を追加します。プロットを作成する順序で凡例の説明を指定します。

title('Linear Combination of Two Functions')
xlabel('Time in \musecs')
ylabel('Magnitude')
legend('a+b','a = sin(x)','b = cos(x)')

Figure contains an axes object. The axes object with title Linear Combination of Two Functions, xlabel Time in mu secs, ylabel Magnitude contains 3 objects of type line, stem. These objects represent a+b, a = sin(x), b = cos(x).

参考

| |