#==========
Julia の修行をするときに,いろいろなプログラムを書き換えるのは有効な方法だ。
以下のプログラムを Julia に翻訳してみる。
三角多項式グラフ
http://aoki2.si.gunma-u.ac.jp/R/Andrews.html
ファイル名: andrewsgraph.jl 関数名: andrewsgraph
翻訳するときに書いたメモ
StatsPlots にある andrewsplot はエラーが出て動かない。
色を指定するときは色の指示も transpose しなければならない(多分これが原因だろう)。
関数内で引数 dat を変更すると,呼び出し側にもその変更は反映される(同じものを操作している)。
==========#
using Statistics, Plots
function andrewsgraph(dat; normalize=true, points=100, col=1, alpha=0.2)
data = copy(dat)
n, nv = size(data)
if normalize
means = mean(data, dims=1)
stds = std(data, dims=1)
for i = 1:nv
data[:, i] = (data[:, i] .- means[i]) ./ stds[i]
end
end
θ = range(-π, π, length=points)
coef = zeros((nv, points))
for i = 2:nv
func = i % 2 == 0 ? sin : cos
coef[i, :] = func.((i ÷ 2) .* θ)
end
coef[1, :] = repeat([1/sqrt(2)], points)
data = transpose(data * coef)
pyplot()
plot(θ, data, color=col, alpha=alpha, grid=false,
yticks=false, yshowaxis=false, label="")
xticks!(range(-π, π, length=5), ["-π", "-π/2", "0", "π/2", "π"],
tick_direction=:out)
end
using RDatasets
iris = dataset("datasets", "iris")
y = Matrix(iris[:, 1:4])
andrewsgraph(y)
col = transpose(vcat(fill(1, 50), fill(2, 50), fill(3, 50)))
andrewsgraph(y, normalize=false, col=col)