2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JuliaのPlotsで、軸の桁や任意の文字列を設定する

Last updated at Posted at 2024-01-26

目的

これをこうしたい。

変更前 変更後
sin.png sin2.png

方法

@sprintfplotのオプションである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を作成してから追記していく派です。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?