目的
これをこうしたい。
変更前 | 変更後 |
---|---|
方法
@sprintf
と plot
のオプションであるformatter
を用いる。
using Plots
using Printf: @sprintf
θ = range(-π,π,100)
fig = plot(
xlabel = "θ",
ylabel = "sinθ",
xformatter = x -> @sprintf("%.1fπ",x/π),
yformatter = y -> @sprintf("%.2f",y),
)
plot!(fig,
θ,
sin.(θ),
label = :none,
)
まとめ
xticks
などで指定する方法もありますが、formatter
も便利そうなので、ぜひいろいろ情報提供いただきたいです。
あと、plot
の引数は縦書きで、Matplotlibのようにfig
を作成してから追記していく派です。