LoginSignup
1
1

More than 5 years have passed since last update.

PyPlot.jl でデフォルトのfigsizeを指定する方法

Posted at

結論

PyCallを使えばできます。

コード

using PyCall
matplotlib = pyimport("matplotlib")

# デフォルトのfigsizeを設定
# ** matplotlib["rcParams"]はPyObjectという型になっているので、Juliaの辞書のようにアクセスするために、PyDict型に包んでから代入する(`setindex!`を呼ぶ)
PyDict(matplotlib["rcParams"])["figure.figsize"] = (10, 5)
# ↑は、以下と等価
# setindex!(PyDict(matplotlib["rcParams"]), (10, 5), "figure.figsize") 

using PyPlot

# 適当な何か
plot(rand(10))

この方法は、すべてのfigureに対して設定を反映したいときに便利です。

PyPlotを使い始めた頃、Juliaからどうすればできるのかわからなかったのですが、PyCallを使えば可能でした。

figureに対して個別にfigsizeを指定したい場合

以下のようにすれば可能です。

using PyPlot

# 指定したfigsizeでfigureを作成
figure(figsize=(16, 6))
# 何か描画
plot(rand(10))

おわり

参考

1
1
0

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
1
1