ujimushi(@旧sradjp(15364))の日記

旧スラドの日記の引越先です

title(location|(font[hv]align))(Plots.jl(GR))追加情報

今回の内容はtitle(|location|font(family|size|color|rotation|[vh]align)) (Plots.jl(GR)) の追加情報になります。

まぁ何というか公式のアトリビュートのドキュメントに

Atrribute Aliases Default Type Description
titlelocation ... :center Symbol ...

ってあったので,シンボル型だとうのみにしていたのだが,どうもタプルでの指定も可能らしい… というのが,この記事の主な内容になります。

一応,titleのポジション指定の概念図を次に示します。 赤字の部分が指定する感じです。 といっても前回のmargin関係の図の流用です。

で,plot_titleで出来たことをtitleでやってみると,うっかり出来てしまったのでここに情報を記録します。 といっても,ほぼ上の概念図で全てなのですが…

使用例

座標指定

まずは座標指定のサンプルです。

using Plots
import GR
gr()

my_pos = [(0,1), (0.5, 1), (1,1),
          (0, 0.5), (0.5, 0.5), (1, 0.5),
          (0, 0), (0.5, 0), (1, 0)]

plts = [plot(sin;title="$(pos)", titleposition=pos, margin=(1, :cm))
        for pos in my_pos]
plot(plts...; size=(1200, 900), layout=(3, 3))
savefig("title_location_coordinate.png")

表示座標内の左下を(0,0),右上を(1,1)とした座標でタイトルの位置を指定することになるようです。

図の下側にタイトルを表示

下側のマージンを大きくしてそこにタイトルを表示する例です。 使うとすればこの例でしょうか?

using Plots
import GR
gr()

plot(sin; title="下の真ん中", titlefontfamily="ipag", titlelocation=(0.5, -0.1),
     bottom_margin=(1, :cm))

savefig("title_location_bottom.png")

titlefont[hv]align

:center:left:rightの時は効かないのですが,座標指定の時は titlefont[hv]alignアトリビュートが効きます。

次は図の真ん中を指定座標にして,アラインを変更したものです。

using Plots
import GR
gr()
my_opt = (titlefontfamily="ipag", titleposition=(0.5, 0.5),
          ticks = 0:0.5:1)

plot(
    plot(;title="左上", titlefonthalign=:right, titlefontvalign=:bottom,
         my_opt...),
    plot(;title="右上", titlefonthalign=:left, titlefontvalign=:bottom,
         my_opt...),
    plot(;title="左下", titlefonthalign=:right, titlefontvalign=:top,
         my_opt...),
    plot(;title="右下", titlefonthalign=:left, titlefontvalign=:top,
         my_opt...),
    layout=(2,2))

savefig("title_align.png")

対応バージョンについて

上記の内容はバージョン1, 2とも利用できる内容です。