Octave で棒グラフを描く
bar(y)
bar(x, y)
bar(..., w)
bar(..., style)
bar(..., prop, val), ...)
bar(hax, ...)
h = bar(..., prop, val), ...)
水平棒グラフは barh()。引数は bar() と同じ。
w: 棒の幅(デフォルトは 0.8)
y が行列の場合は列ごとの棒グラフを描く。
style: "grouped"(デフォルト) 隣り合わせに配置
"stacked" 積み上げ棒グラフ
"hist" 棒の間に隙間を置かない。中央揃え
"histc" 左揃え
prop, value の対
"facecolor", "edgecolor"
"r", "g", "b", "k", "none", [r g b] など
h: 戻り値は,作られた棒グラフのハンドルベクトル(使用例参照)
pkg load statistics
clf;
y = binopdf(0:10, 10, 0.35);
bar(0:10, y, "facecolor", [0.9297 0.9648 1])
box off % default is on 図の外枠を描かない
set(gca, "tickdir", "out") % ティックマークを外側に描く
xlim([-1, 11])
ylim([0, 0.3])
title("binomial distribution\nn = 10, p = 0.35")
xlabel("x")
ylabel("p")
set(gca, "fontsize", 18) % 一括して変更するとき
pkg load statistics
y = [binopdf(0:10, 10, 0.15)', binopdf(0:10, 10, 0.35)', binopdf(0:10, 10, 0.5)'];
clf;
h = bar(0:10, y, "hist");
set(h(1), "facecolor", [0.9297 0.9648 1]);
set(h(2), "facecolor", [0.8 0.9 0.5]);
set(h(3), "facecolor", [0.9 0.7 0.6]);
box off % default is on 図の外枠を描かない
set(gca, "tickdir", "out") % ティックマークを外側に描く
xlim([-1, 11])
ylim([0, 0.35])
title("binomial distribution\nn = 10, p = [0.15, 0.35, 0.50]")
xlabel("x")
ylabel("p")
set(gca, "fontsize", 18) % 一括して変更するとき
pkg load statistics
y = [binopdf(0:10, 10, 0.15)', binopdf(0:10, 10, 0.35)', binopdf(0:10, 10, 0.5)'];
clf;
h = barh(0:10, y, "histc");
set(h(1), "facecolor", [0.9297 0.9648 1]);
set(h(2), "facecolor", [0.8 0.9 0.5]);
set(h(3), "facecolor", [0.9 0.7 0.6]);
box off % default is on 図の外枠を描かない
set(gca, "tickdir", "out") % ティックマークを外側に描く
ylim([-1, 11])
xlim([0, 0.35])
title("binomial distribution\nn = 10, p = [0.15, 0.35, 0.50]")
ylabel("x")
xlabel("p")
set(gca, "fontsize", 18) % 一括して変更するとき
pkg load statistics
y = [binopdf(0:10, 10, 0.15)', binopdf(0:10, 10, 0.35)', binopdf(0:10, 10, 0.5)'];
clf;
h = barh(0:10, y, "stacked");
set(h(1), "facecolor", [0.9297 0.9648 1]);
set(h(2), "facecolor", [0.8 0.9 0.5]);
set(h(3), "facecolor", [0.9 0.7 0.6]);
box off % default is on 図の外枠を描かない
set(gca, "tickdir", "out") % ティックマークを外側に描く
ylim([-1, 11])
xlim([0, 0.55])
title("binomial distribution\nn = 10, p = [0.15, 0.35, 0.50]")
ylabel("x")
xlabel("p")
set(gca, "fontsize", 18) % 一括して変更するとき