Main Content

一般的な 2 次元プロットプロットの作成

この例では、MATLAB® でさまざまな 2 次元プロットを作成する方法を示します。

ライン プロット

関数 plotx 値と y 値の簡単なライン プロットを作成します。

x = 0:0.05:5;
y = sin(x.^2);
figure
plot(x,y)

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

ライン プロットは xy のデータの複数のセットを表示できます。

y1 = sin(x.^2);
y2 = cos(x.^2);
plot(x,y1,x,y2)

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

棒グラフ

関数 bar は縦の棒グラフを作成します。関数 barh は横の棒グラフを作成します。

x = -2.9:0.2:2.9;
y = exp(-x.*x);
bar(x,y)

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

階段状プロット

関数 stairs は階段状プロットを作成します。Y 値のみの階段状プロット、あるいは x 値と y 値の階段状プロットを作成することが可能です。

x = 0:0.25:10;
y = sin(x);
stairs(x,y)

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

エラー バー プロット

関数 errorbarx 値と y 値のライン プロットを描画し、垂直の誤差範囲を各観測値に重ね合わせます。誤差範囲のサイズを指定するには、追加の入力引数を関数 errorbar に渡します。

x = -2:0.1:2;
y = erf(x);
eb = rand(size(x))/7;
errorbar(x,y,eb)

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

極座標プロット

関数 polarplot は、theta (ラジアン単位) の角度値と rho の半径値を組み合わせた極座標プロットを描画します。

theta = 0:0.01:2*pi;
rho = abs(sin(2*theta).*cos(2*theta));
polarplot(theta,rho)

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

ステム プロット

関数 stem は、共通のベースラインに接続する垂直線を使って、xy の各値に対するマーカーを描画します。

x = 0:0.1:4;
y = sin(x.^2).*exp(-x);
stem(x,y)

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

散布図

関数 scatter は、x 値と y 値の散布図を描画します。

load patients Height Weight Systolic
scatter(Height,Weight)
xlabel('Height')
ylabel('Weight')

Figure contains an axes object. The axes object with xlabel Height, ylabel Weight contains an object of type scatter.

関数 scatter にオプションの引数を使用して、マーカーのサイズと色を指定します。関数 colorbar を使用して、現在の座標軸のカラー スケールを表示します。

scatter(Height,Weight,20,Systolic)
xlabel('Height')
ylabel('Weight')
colorbar

Figure contains an axes object. The axes object with xlabel Height, ylabel Weight contains an object of type scatter.

関連するトピック