violinplot, swarmplotのそれぞれとboxplotを比較してみた.
以下のtwitterでのスレッドも参照:
using Seaborn: Seaborn
const sns = Seaborn
# issue?
sns.@delegate despine
using PyCall
const pd = pyimport("pandas")
using Distributions
using Statistics
using Random: seed!
seed!(2019)
n = 2^10
dist0 = Normal(0, 3.3)
Y0 = rand(dist0, n)
dist1 = MixtureModel(
[Normal(-6.5, 1.5), Normal(0.0, 1.4), Normal(6.5, 1.5)],
[0.22, 0.56, 0.22]
)
Y1 = rand(dist1, n)
println("std(first sample) = ", std(Y0))
println("std(second sample) = ", std(Y1))
sns.figure(figsize=(9,3))
sns.subplot(131)
sns.title("boxplot")
sns.boxplot(data=[Y0, Y1], palette="pastel")
despine(left=true)
sns.subplot(132)
sns.title("violinplot")
sns.violinplot(data=[Y0, Y1], inner="quartile", palette="pastel")
despine(left=true)
sns.subplot(133)
sns.title("swarmplot")
sns.swarmplot(data=[Y0, Y1], size=1.5)
despine(left=true)
sns.tight_layout()
std(first sample) =
3.2134179655166135 std(second sample) = 4.4335909115663075
seed!(2019)
n = 2^9
dist0 = Uniform(-10, 10)
Y0 = rand(dist0, n)
dist1 = MixtureModel(
[Uniform(-10,-9), Uniform(-6,6), Uniform(9,10)],
[0.2, 0.6, 0.2]
)
Y1 = rand(dist1, n)
println("std(first sample) = ", std(Y0))
println("std(second sample) = ", std(Y1))
sns.figure(figsize=(9,3))
sns.subplot(131)
sns.title("boxplot")
sns.boxplot(data=[Y0, Y1], palette="pastel")
despine(left=true)
sns.subplot(132)
sns.title("violinplot")
sns.violinplot(data=[Y0, Y1], inner="quartile", palette="pastel")
despine(left=true)
sns.subplot(133)
sns.title("swarmplot")
sns.swarmplot(data=[Y0, Y1], size=2)
despine(left=true)
sns.tight_layout()
std(first sample) = 5.715486884410333 std(second sample) = 6.539527618105898
seed!(2019)
n = 2^10
dist0 = Normal(0, 3.3)
Y0 = rand(dist0, n)
dist1 = MixtureModel(
[Normal(-6.5, 1.5), Normal(0.0, 1.4), Normal(6.5, 1.5)],
[0.22, 0.56, 0.22]
)
Y1 = rand(dist1, n)
println("std(first sample) = ", std(Y0))
println("std(second sample) = ", std(Y1))
sns.figure(figsize=(9,3))
sns.subplot(131)
sns.title("boxplot")
sns.boxplot(data=[Y0, Y1], palette="pastel")
despine(left=true)
sns.subplot(132)
sns.title("violinplot")
sns.violinplot(data=[Y0, Y1], inner="quartile", palette="pastel")
despine(left=true)
sns.subplot(133)
sns.title("swarmplot")
sns.swarmplot(data=[Y0, Y1], size=1.5)
sns.boxplot(data=[Y0, Y1],
medianprops=Dict("linestyle"=>"--", "linewidth"=>1),
boxprops=Dict("facecolor"=>"None", "linestyle"=>"--", "linewidth"=>1),
whiskerprops=Dict("linestyle"=>"-", "linewidth"=>1.5),
capprops=Dict("linestyle"=>"--", "linewidth"=>1),
flierprops=Dict("markeredgecolor"=>"k", "markersize"=>1.5))
despine(left=true)
sns.tight_layout()
std(first sample) = 3.2134179655166135 std(second sample) = 4.4335909115663075
seed!(2019)
n = 2^9
dist0 = Uniform(-10, 10)
Y0 = rand(dist0, n)
dist1 = MixtureModel(
[Uniform(-10,-9), Uniform(-6,6), Uniform(9,10)],
[0.2, 0.6, 0.2]
)
Y1 = rand(dist1, n)
println("std(first sample) = ", std(Y0))
println("std(second sample) = ", std(Y1))
sns.figure(figsize=(9,3))
sns.subplot(131)
sns.title("boxplot")
sns.boxplot(data=[Y0, Y1], palette="pastel")
despine(left=true)
sns.subplot(132)
sns.title("violinplot")
sns.violinplot(data=[Y0, Y1], inner="quartile", palette="pastel")
despine(left=true)
sns.subplot(133)
sns.title("swarmplot")
sns.swarmplot(data=[Y0, Y1], size=2)
sns.boxplot(data=[Y0, Y1],
medianprops=Dict("linestyle"=>"--", "linewidth"=>1),
boxprops=Dict("facecolor"=>"None", "linestyle"=>"--", "linewidth"=>1),
whiskerprops=Dict("linestyle"=>"-", "linewidth"=>1.5),
capprops=Dict("linestyle"=>"--", "linewidth"=>1),
flierprops=Dict("markeredgecolor"=>"k", "markersize"=>2))
despine(left=true)
sns.tight_layout()
std(first sample) = 5.715486884410333 std(second sample) = 6.539527618105898
seed!(2019)
n = 2^10
dist0 = Normal(0, 3.3)
Y0 = rand(dist0, n)
dist1 = MixtureModel(
[Normal(-6.5, 1.5), Normal(0.0, 1.4), Normal(6.5, 1.5)],
[0.22, 0.56, 0.22]
)
Y1 = rand(dist1, n)
println("std(first sample) = ", std(Y0))
println("std(second sample) = ", std(Y1))
sns.figure(figsize=(9,3))
sns.subplot(131)
sns.title("boxplot")
sns.boxplot(data=[Y0, Y1], palette="pastel")
despine(left=true)
sns.subplot(132)
sns.title("violinplot")
sns.violinplot(data=[Y0, Y1], palette="pastel", cut=0, bw=0.1)
despine(left=true)
sns.subplot(133)
sns.title("swarmplot")
sns.swarmplot(data=[Y0, Y1], size=1.5)
sns.boxplot(data=[Y0, Y1],
medianprops=Dict("linestyle"=>"--", "linewidth"=>1),
boxprops=Dict("facecolor"=>"None", "linestyle"=>"--", "linewidth"=>1),
whiskerprops=Dict("linestyle"=>"-", "linewidth"=>1.5),
capprops=Dict("linestyle"=>"--", "linewidth"=>1),
flierprops=Dict("markeredgecolor"=>"k", "markersize"=>1.5))
despine(left=true)
sns.tight_layout()
std(first sample) = 3.2134179655166135 std(second sample) = 4.4335909115663075
seed!(2019)
n = 2^9
dist0 = Uniform(-10, 10)
Y0 = rand(dist0, n)
dist1 = MixtureModel(
[Uniform(-10,-9), Uniform(-6,6), Uniform(9,10)],
[0.2, 0.6, 0.2]
)
Y1 = rand(dist1, n)
println("std(first sample) = ", std(Y0))
println("std(second sample) = ", std(Y1))
sns.figure(figsize=(9,3))
sns.subplot(131)
sns.title("boxplot")
sns.boxplot(data=[Y0, Y1], palette="pastel")
despine(left=true)
sns.subplot(132)
sns.title("violinplot")
sns.violinplot(data=[Y0, Y1], palette="pastel", cut=0, bw=0.05)
despine(left=true)
sns.subplot(133)
sns.title("swarmplot")
sns.swarmplot(data=[Y0, Y1], size=2)
sns.boxplot(data=[Y0, Y1],
medianprops=Dict("linestyle"=>"--", "linewidth"=>1),
boxprops=Dict("facecolor"=>"None", "linestyle"=>"--", "linewidth"=>1),
whiskerprops=Dict("linestyle"=>"-", "linewidth"=>1.5),
capprops=Dict("linestyle"=>"-", "linewidth"=>1),
flierprops=Dict("markeredgecolor"=>"k", "markersize"=>2))
despine(left=true)
sns.tight_layout()
std(first sample) = 5.715486884410333 std(second sample) = 6.539527618105898
sns.set(style="whitegrid", palette="pastel", color_codes=true)
# Load the example tips dataset
tips = sns.load_dataset("tips")
# Draw a nested violinplot and split the violins for easier comparison
sns.violinplot(x="day", y="total_bill", hue="smoker",
split=true, inner="quart",
palette=Dict("Yes"=>"y", "No"=>"b"),
data=tips)
sns.legend(loc="upper left")
despine(left=true);
sns.boxplot(x="day", y="total_bill", hue="smoker",
palette=Dict("Yes"=>"y", "No"=>"b"),
data=tips)
despine(left=true);
sns.set(style="whitegrid", palette="muted")
# Load the example iris dataset
iris = sns.load_dataset("iris")
# "Melt" the dataset to "long-form" or "tidy" representation
iris = pd.melt(iris, "species", var_name="measurement")
# Draw a categorical scatterplot to show each observation
sns.swarmplot(x="measurement", y="value", hue="species",
palette=["r", "c", "y"], data=iris);
sns.boxplot(x="measurement", y="value", hue="species",
palette=["r", "c", "y"], data=iris);
sns.set(style="ticks", palette="pastel")
# Load the example tips dataset
tips = sns.load_dataset("tips")
# Draw a nested boxplot to show bills by day and time
sns.boxplot(x="day", y="total_bill",
hue="smoker", palette=["m", "g"],
data=tips)
despine(offset=10, trim=true)
sns.violinplot(x="day", y="total_bill",
hue="smoker", palette=["m", "g"],
data=tips)
despine(offset=10, trim=true)
sns.set(style="ticks", palette="bright")
sns.swarmplot(x="day", y="total_bill",
hue="smoker", palette=["m", "g"],
data=tips)
despine(offset=10, trim=true)
sns.figure(figsize=(14, 4))
sns.subplot("131")
sns.set(style="ticks", palette="pastel")
sns.boxplot(x="day", y="total_bill",
hue="smoker", palette=["m", "g"],
data=tips)
sns.title("boxplot")
despine(offset=10, trim=true)
sns.subplot("132")
sns.set(style="ticks", palette="pastel")
sns.violinplot(x="day", y="total_bill",
hue="smoker", palette=["m", "g"],
data=tips)
sns.title("violinplot")
despine(offset=10, trim=true)
sns.subplot("133")
sns.set(style="ticks", palette="bright")
sns.swarmplot(x="day", y="total_bill",
hue="smoker", palette=["m", "g"],
data=tips)
sns.title("swarmplot")
despine(offset=10, trim=true)
sns.tight_layout()