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

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

legend_title他(Plots.jl(GR))

世界で一番細か過ぎるし役に立たないPlots.jl情報。 今日はおそらく今後一回も使わないだろうと思われるlegend_title関連のアトリビュートを紹介しましょう。

今回はネタ回みたいなものです。特にMacユーザーの人には全く参考にならないと思います。すみません。

legend_title

legend_titleとは何か?。実例を見るのが一番いいでしょう。

using Plots
gr()

plot([sin, cos]; legend_title="三角関数",
     legend_title_font_family="JuiseeHWSZ-Regular",
     legend_font_family="JuiseeHWSZ-Regular",
     label=["正弦" "余弦"])

savefig("legend-title-example.png")

そうです。凡例のタイトルを表示するアトリビュートです。 legend_font系の記事とほぼ同じ内容になると思います。 種類と別名を次に一気に例示します。

  • legend_title
    • key_title, keytitle, label_title, labeltitle, leg_title, legend_titles, legendtitle, legendtitles, legtitl
  • legend_title_font
    • legend_title_fonts, legendtitlefont, legendtitlefonts
  • legend_title_font_color
    • legend_title_font_colors, legendtitlefontcolor, legendtitlefontcolors
  • legend_title_font_family
    • legend_title_font_familys, legendtitlefontfamily, legendtitlefontfamilys
  • legend_title_font_halign
    • legend_title_font_haligns, legendtitlefonthalign, legendtitlefonthaligns
  • legend_title_font_pointsize
    • legend_title_font_pointsizes, legendtitlefontpointsize, legendtitlefontpointsizes, legendtitlefontsize
  • legend_title_font_rotation
    • legend_title_font_rotations, legendtitlefontrotation, legendtitlefontrotations
  • legend_title_font_valign
    • legend_title_font_valigns, legendtitlefontvalign, legendtitlefontvaligns

まぁ,後は使用例を例示するぐらいでいいですかね。

legend_title_font_halign, legend_title_font_valign

まずは例をご覧下さい。

using Plots
gr()

plts = [plot([sin, cos]; legend_title="$(x), $(y)", label=["sin" "cos"],
             legend_position=(0.3, 0.5),
             legend_title_font_halign=x, legend_title_font_valign=y)
        for x in [:left, :center, :hcenter, :right],
            y in [:top, :center, :vcenter, :bottom]]
plt = plot(plts..., plot_title="legend_title_font_[hv]align",
           size=(1024, 1024), layout=(4, 4))
savefig(plt, "legend_title_font_hvalign.png")

凡例の上方真ん中に基準として,文字列の基準をそれぞれhalignvalignで設定したものに合わせる という感じで,halign系はほぼ:(h)centerしか役に立ちません。 valign:(v)center以外はおさまりが悪く設定は変えられるけど使えないオプションのような感じです。

legend_title_font_color, legend_title_font_pointsize

次の実例を見ていただいて分かる通り,凡例のタイトルの色とサイズを変えるアトリビュートです。 特にありません。

using Plots
gr()

plts = [plot([sin, cos]; label=["sin" "cos"], legend_position=(0.1, 0.5),
             legend_title="$x, $y", 
             legend_title_font_color=x,
             legend_title_font_pointsize=y)
        for x in [:black, :red, :blue, :green], y in 6:2:12]
plt = plot(plts..., plot_title="legend_title_font_(color|pointsize)", layout=(4, 4), size=(800, 800))
savefig(plt, "legend-title-font-color-pointsize.png")

legend_title_font_rotation

凡例タイトルを回転させるアトリビュートです。下に示す実例を見ると, legend_font_lotationよりはだいぶまともな結果です。これは,回転の中心が文字列の真ん中になっているからですが, 縦方向に長くなると,凡例の間隔が自動的に広がって凡例のバランスが崩れるのであまり実用性はない感じです。

using Plots
gr()

plts = [plot([sin, cos]; label=["sin" "cos"], legend_position=(0.5, 0.7),
             legend_title="$(x)", 
             legend_title_font_rotation=x)
        for x in 0:30:330]
plt = plot(plts..., plot_title="legend_title_font_rotation", layout=(3, 4), size=(800, 600))
savefig(plt, "legend-title-font-rotation.png")

legend_title_font_family

フォントの種類指定です。一応標準フォント一覧の例。

using Plots
gr()
default(legend_position=(0.1, 0.7), legend_title_font_pointsize=14)
font_names = [
    "times", "helvetica", "courier", "bookman",
    "newcenturyschlbk", "avantgarde", "palatino", "serif-roman",
    "sans-serif"
]
plts = [plot(sin; legend_title_font_family=f, legend_title="$f") for f in font_names]
plot(plts...; layout=(3,3), size=(800, 500))
savefig("legend-title-font-family.png")

legend_title_font

Plots.Font型を指定しての凡例のアトリビュート指定になります。 特にないです。と思ったのですが,

どうもうまく設定が反映されないようです。 結局,暗黙のlegend_title_font_*のデフォルト値で上書きされていてFont型での指定は効かなさそうです。これは注意ですね。多分今後使わないけど。

using Plots
gr()
myfont = font(family="JuiseeHWSZ-Regular", color=:green, pointsize=8, rotation=180)
plt = plot(sin; legend_title="日本語", legend_title_font=myfont)
savefig(plt, "legend-title-font.png")

まとめ

今後誰も使わないと思われるlegend_title*アトリビュートについて紹介しました。 役に立つ情報は他のサイトに任せて,どんどん役に立たない情報を中心に記事にしていきたいと思います。