Open8
Juliaでプロットいろいろメモ
juliaでquiver plot
quiver(x_start, y_start, x_add, y_add)
quiver([1,2,3],[3,2,1],quiver=([1,1,1],[1,2,3]))
xe = range(-1, 1, length=15)
ye = range(-1, 1, length=15)
x = repeat(xe, outer=length(ye))
y = repeat(ye, inner=length(xe));
u = y
v = x
k = 0.1
quiver(x, y, quiver=(k*u, k*v))
参考サイト)
複数プロットする方法
xs = range(0, 20, length = 21)
μs = [0.2, 0.4, 0.6, 0.8]
plt = []
for i in 1:4
μ = μs[i]
d = Binomial(20, μ)
push!(plt, bar(xs, pdf.(d, xs), label = "μ=$(μ)"))
end
plot(plt..., layout = (2, 2), size = (400, 400))
xs = 0:60
rs = [3, 5, 10]
μs = [0.3, 0.5, 0.7]
plt = []
for i in 1:length(rs)
for j in 1:length(μs)
d = NegativeBinomial(rs[i], μs[j])
push!(plt, bar(xs, pdf.(d, xs), label = "μ=$(μs[i]), r=$(rs[i])"))
end
end
plot(plt...)
μ = [0.0, 0.0]
Σ = [0.01 0.0;
0.0 0.01]
X = [-10, -5, 0, 5, 10]
num_samples = 3
W = rand(MvNormal(μ, Σ), num_samples)
Ys = []
xs = range(-12, 12, length = 100)
plt1 = plot()
plt2 = plot()
for n in 1:num_samples
w1, w2 = W[:, n]
scatter!(plt1, (w1, w2))
f(x) = sig(w1 * x + w2)
plot!(plt2, xs, f.(xs))
Y = rand.(Bernoulli.(f.(X)))
push!(Ys, Y)
end
plot(plt1, plt2, size = (800, 400))
bar()関数
d = Bernoulli(0.3)
bar([0,1], pdf.(d, [0, 1]))
histogram()関数
d = Bernoulli(0.3)
x = rand(d, 10000)
b_range = range(0, 20, length=20)
histogram(x, bins=b_range)
contour()関数
μ = [0.0, 0.0]
Σ = [1.0 0.5;
0.5 1.0]
d = MvNormal(μ, Σ)
x = rand(d, 100)
contour(
xs1, xs2,
[pdf(d, [x1, x2]) for x1 in xs1, x2 in xs2],
# contour_labels=true
clabels = true,
levels = 0.025:0.025:0.150
)