<style> .reveal, .reveal h1, .reveal h2, .reveal h3, .reveal h4, .reveal h5, .reveal h6 { font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, "Microsoft JhengHei", Meiryo, sans-serif; } h1, h2, h3, h4, h5, h6 { text-transform: none !important; } .color-yellow{ color: yellow; } .alert { padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; text-align: left; padding: 10px 0; } .alert-info { color: #31708f; background-color: #d9edf7; border-color: #bce8f1; } .alert-success { color: #3c763d; background-color: #dff0d8; border-color: #d6e9c6; } .alert-danger { color: #a94442; background-color: #f2dede; border-color: #ebccd1; } .reveal .slides span { text-align: left; display: inline-block; } p, li { font-size: 0.88em !important; } li>p { font-size: 1em !important; } </style> # RecipesBase.jlで<br>プロットレシピを<br>定義しよう! [堀川 由人, ほりたみゅ, @Hyrodium](https://hyrodium.github.io/ja) ---- 回転行列を可視化したりする事例紹介です ```julia using Plots, Rotations; plotly() plot(rand(QuatRotation)) ``` <iframe src="https://hyrodium.github.io/memomemo/2024-03-16_plotly-example/rotation1.html" width="700" height="450" frameborder="0" style="border:0" allowfullscreen></iframe> ---- ### おしながき * 自己紹介 * Plots.jl便利ですよね * RecipesBase.jl事例紹介 * まとめ & 感想 --- ### 自己紹介 * [堀川 由人, ほりたみゅ, @Hyrodium](https://hyrodium.github.io/ja) * [GitHub](https://github.com/hyrodium) / [Bluesky](https://bsky.app/profile/hyrodium.bsky.social) / [Twitter](https://twitter.com/Hyrodium) 近況報告: 寝室に天井プロジェクターを設置したら就寝のモチベーションが上がって夜更しが減りました ![image](https://hackmd.io/_uploads/HkcjgKz06.png =450x) --- ### Plots.jl便利ですよね * Plots.jlの使用例 * バックエンド切り替え ---- #### Plots.jlの使用例 皆さんご存知かと思いますが ```julia using Plots plot(sin) histogram!(randn(100000), normalize=true) ``` ![image](https://hackmd.io/_uploads/BJbDEKzRp.png) ---- #### バックエンド切り替え (unicodeplots) ```julia unicodeplots() plot(sin) histogram!(randn(100000), normalize=true) ``` ![image](https://hackmd.io/_uploads/Sk0c4tz06.png) ---- #### バックエンド切り替え (plotly) ```julia plotly() plot(sin) histogram!(randn(100000), normalize=true) ``` <iframe src="https://hyrodium.github.io/memomemo/2024-03-16_plotly-example/plot1.html" width="700" height="450" frameborder="0" style="border:0" allowfullscreen></iframe> --- ### RecipesBase.jl事例紹介 * [RecipesBase.jl](https://github.com/JuliaPlots/Plots.jl/tree/master/RecipesBase)とは? * [Rotations.jl](https://github.com/JuliaGeometry/Rotations.jl)でのレシピ例 * [IntervalSets.jl](https://github.com/JuliaMath/IntervalSets.jl)でのレシピ例 * [BasicBSpline.jl](https://github.com/hyrodium/BasicBSpline.jl)でのレシピ例 ---- #### RecipesBase.jlとは? * モチベーション * `hoge::Hoge` ← 自分で定義した型のインスタンス * `plot(hoge)`で良い感じにプロットして欲しい! * どうやって実現するか? * 多重ディスパッチでプロットに関するメソッド追加! * `RecipesBase.@recipe`を使えば簡単 * バックエンドごとにコードを書かなくてOK! ---- #### Rotations.jl (四元数回転の可視化) ```julia! using Rotations, Plots; plotly() plot(one(QuatRotation)) plot!(QuatRotation(1/√2, 1/√2, 0, 0); origin=(1,0,0)) ``` <iframe src="https://hyrodium.github.io/memomemo/2024-03-16_plotly-example/rotation2.html" width="700" height="450" frameborder="0" style="border:0" allowfullscreen></iframe> ---- #### Rotations.jl (Slerpの可視化) ```julia! using Rotations, Plots; plotly() R1, R2 = rand(QuatRotation, 2) plot(R1; linewidth=3, label="R1") plot!(R2; linewidth=3, label="R2", origin=(1,0,0)) N = 12 for i in 2:N-1 plot!(slerp(R1,R2,i/N); linewidth=3, label=nothing, origin=(i/N,0,0), boxsize=0.0, axissize=3/4) end plot!() ``` <iframe src="https://hyrodium.github.io/memomemo/2024-03-16_plotly-example/rotation3.html" width="700" height="450" frameborder="0" style="border:0" allowfullscreen></iframe> ---- #### Rotations.jl (2次元もOK) ```julia using Rotations, Plots plot(Angle2d(0.2); aspectratio=1) plot!(Angle2d(0.3); aspectratio=1) ``` ![image](https://hackmd.io/_uploads/SJI6OFzA6.png) ---- #### IntervalSets.jl (端点の開閉に対応) ```julia using IntervalSets, Plots plot(iv"(1,2)"); plot!(iv"[3,6)"); plot!(iv"[5,7)") ``` ![image](https://hackmd.io/_uploads/B1WyiFfCp.png) ---- #### IntervalSets.jl (開は透過でなく背景色) ```julia using IntervalSets, Plots plot(iv"[1,3]"); plot!(iv"(2,4)") ``` ![image](https://hackmd.io/_uploads/BkPmitzAp.png) ---- #### IntervalSets.jl (`offset`キーワード引数) ```julia using IntervalSets, Plots plot(iv"[1,3]"); plot!(iv"(2,4)"; offset=-0.1, ylims=(-1,1)) ``` ![image](https://hackmd.io/_uploads/rkBOotf06.png) ---- #### BasicBSpline.jl (ノット列の可視化) ノット列: 広義単調増加な実軸上の有限列 ```julia using Plots, BasicBSpline k = KnotVector([0,0,1,2,3,3,5,8,8,9]) plot(k; ylims=(-0.5,0.5), yticks=nothing) ``` ![image](https://hackmd.io/_uploads/SJZek9zAa.png) ---- #### BasicBSpline.jl (区分多項式空間の可視化) B-spline空間: ノットを区分点に持つ区分多項式全体 B-spline基底関数: B-spline空間の基底で性質の良いやつ ```julia P = BSplineSpace{2}(k) plot(P) plot!(k) ``` ![image](https://hackmd.io/_uploads/HyW7y5MAa.png) ---- #### BasicBSpline.jl (B-spline曲線の可視化) B-spline曲線: B-spline基底関数と制御点の線型結合 ```julia a = rand(SVector{2, Float64}, dim(P)) M = BSplineManifold(a, P) plot(M) ``` ![image](https://hackmd.io/_uploads/SJrRJ5MCT.png) --- ### まとめ & 感想 * RecipesBase.jlで定義するプロットレシピ便利! * 実装はPRなど参照ください * [Rotations.jl #284](https://github.com/JuliaGeometry/Rotations.jl/pull/284) * [IntervalSets.jl #182](https://github.com/JuliaMath/IntervalSets.jl/pull/182) * [BasicBSpline.jl #370](https://github.com/hyrodium/BasicBSpline.jl/pull/370) * 他にも良い記事あるので参照されたし * [Plots.jl入門](https://zenn.dev/ohno/articles/3101433fbe9231) * [Julia / Plots の Recipe を使ってプロットを定型化する](https://qiita.com/Lirimy/items/f49d9dce3600ee14dcc4) * [Plots.jl v2](https://github.com/JuliaPlots/Plots.jl/pull/4904)が楽しみ! * バックエンドがすべてweakdepsになるらしい * [Desmos.jl](https://github.com/hyrodium/Desmos.jl)のバックエンド追加チャンス!
{"lang":"ja","dir":"ltr","robots":"noindex, nofollow","slideOptions":"{\"theme\":\"white\",\"transition\":\"slide\"}","title":"JuliaTokai #18 (2024-03-16)","description":"堀川 由人, ほりたみゅ, @Hyrodium","breaks":true,"contributors":"[{\"id\":\"41421433-16a1-4a57-ac11-6f7b7becb765\",\"add\":6691,\"del\":672}]"}
    335 views