shorter implementation

This commit is contained in:
Daniel Schwabeneder 2019-05-01 12:12:51 +02:00
parent 03325533bf
commit 903cb404c3

View File

@ -1268,29 +1268,19 @@ const _pyplot_legend_pos_outer = KW(
py_legend_pos(pos::Symbol) = get(_pyplot_legend_pos, pos, get(_pyplot_legend_pos_outer, pos, "best")) py_legend_pos(pos::Symbol) = get(_pyplot_legend_pos, pos, get(_pyplot_legend_pos_outer, pos, "best"))
py_legend_pos(pos) = "lower left" py_legend_pos(pos) = "lower left"
function py_legend_bbox_outer(pos, ax) const _pyplot_legend_bbox_outer = KW(
pos_str = string(pos) :outerright => (1.0, 0.5, 0.0, 0.0),
hor = if occursin("left", pos_str) :outerleft => (-0.15, 0.5, 0.0, 0.0),
-0.15 :outertop => (0.5, 1.0, 0.0, 0.0),
elseif occursin("right", pos_str) :outerbottom => (0.5, -0.15, 0.0, 0.0),
1.0 :outerbottomleft => (-0.15, 0.0, 0.0, 0.0),
else :outerbottomright => (1.0, 0.0, 0.0, 0.0),
0.5 :outertopright => (1.0, 1.0, 0.0, 0.0),
end :outertopleft => (-0.15, 1.0, 0.0, 0.0)
ver = if pos == :outerbottom )
-0.15
elseif occursin("bottom", pos_str)
0.0
elseif occursin("top", pos_str)
1.0
else
0.5
end
return hor, ver, 0.0, 0.0
end
py_legend_bbox(pos::Symbol, ax) = pos in keys(_pyplot_legend_pos_outer) ? py_legend_bbox_outer(pos, ax) : (0.0, 0.0, 1.0, 1.0) py_legend_bbox(pos::Symbol) = get(_pyplot_legend_bbox_outer, pos, (0.0, 0.0, 1.0, 1.0))
py_legend_bbox(pos, ax) = pos py_legend_bbox(pos) = pos
function py_add_legend(plt::Plot, sp::Subplot, ax) function py_add_legend(plt::Plot, sp::Subplot, ax)
leg = sp[:legend] leg = sp[:legend]
@ -1330,7 +1320,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
leg = ax."legend"(handles, leg = ax."legend"(handles,
labels, labels,
loc = py_legend_pos(leg), loc = py_legend_pos(leg),
bbox_to_anchor = py_legend_bbox(leg, ax), bbox_to_anchor = py_legend_bbox(leg),
scatterpoints = 1, scatterpoints = 1,
fontsize = py_thickness_scale(plt, sp[:legendfontsize]), fontsize = py_thickness_scale(plt, sp[:legendfontsize]),
facecolor = py_color(sp[:background_color_legend]), facecolor = py_color(sp[:background_color_legend]),