julia の PyPlot + seaborn で、2枚のグラフを並べる subplot() と、枠のスタイル sns.set_style() と、軸目盛の plt[:xticks]() の 例

julia の PyPlot + seaborn で、2枚のグラフを並べるの方法と、スタイルあれこれの例です。そのまま、コピー&ペーストして下さい。

(1) デフォルト darkgrid

using PyCall, PyPlot
@pyimport seaborn as sns
x = linspace(0,2pi,100)

sns.set() # デフォルト sns.set_style("darkgrid") と同じ

subplot(211)
ax1 = plot(x,sin.(x),  label="sin(x)")
ylabel("sin(x)", color=sns.color_palette()[1])
plt[:legend]()

subplot(212)
ax2 = plot(x,2cos.(x) , color=sns.color_palette()[2], label="2cos(x)")
ylabel("2cos(x)",  color=sns.color_palette()[2])
plt[:legend]()

(2) ticks

using PyCall, PyPlot
@pyimport seaborn as sns
x = linspace(0,2pi,100)

sns.set_style("ticks")

subplot(211)
ax1 = plot(x,sin.(x),  label="sin(x)")
ylabel("sin(x)", color=sns.color_palette()[1])
plt[:legend]()

subplot(212)
ax2 = plot(x,2cos.(x) , color=sns.color_palette()[2], label="2cos(x)")
ylabel("2cos(x)",  color=sns.color_palette()[2])
plt[:legend]()

(3) ticks + despine で、上と右の枠外し

using PyCall, PyPlot
@pyimport seaborn as sns
x = linspace(0,2pi,100)

sns.set_style("ticks")

subplot(211)
ax1 = plot(x,sin.(x),  label="sin(x)")
ylabel("sin(x)", color=sns.color_palette()[1])
plt[:legend]()

subplot(212)
ax2 = plot(x,2cos.(x) , color=sns.color_palette()[2], label="2cos(x)")
ylabel("2cos(x)",  color=sns.color_palette()[2])
plt[:legend]()

sns.despine()

subplot() で描くと、Y軸のケタ表示が異っても、グラフ領域の大きさは同じになるのは、ちょっと、すばらしいです。

さらに、オマケで、軸目盛を、π (=3.14...) 毎に変更します。

using PyCall, PyPlot
@pyimport seaborn as sns
x = linspace(0,2pi,100)

sns.set_style("ticks")

subplot(211)
ax1 = plot(x,sin.(x),  label="sin(x)")
ylabel("sin(x)", color=sns.color_palette()[1])
plt[:legend]()
plt[:xticks]([0,pi,2pi], ["0", "π","2π"])


subplot(212)
ax2 = plot(x,2cos.(x) , color=sns.color_palette()[2], label="2cos(x)")
ylabel("2cos(x)",  color=sns.color_palette()[2])
plt[:legend]()

sns.despine()

plt[:xticks]([0,pi,2pi], ["0", "π","2π"])

B! LINE