allow numeric legend positioning in pyplot

This commit is contained in:
Daniel Schwabeneder 2019-04-30 15:25:08 +02:00
parent e860ba220a
commit 4742ec972b
2 changed files with 9 additions and 2 deletions

View File

@ -784,7 +784,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
tbx, tby = gr_inqtext(0, 0, string(lab))
legendw = max(legendw, tbx[3] - tbx[1])
end
GR.setscale(1)
GR.selntran(1)
GR.restorestate()

View File

@ -1251,6 +1251,12 @@ const _pyplot_legend_pos = KW(
:topleft => "upper left"
)
py_legend_pos(pos::Symbol) = get(_pyplot_legend_pos, pos, "best")
py_legend_pos(pos) = "lower left"
py_legend_bbox(pos::Symbol) = (0, 0, 1, 1)
py_legend_bbox(pos) = pos
function py_add_legend(plt::Plot, sp::Subplot, ax)
leg = sp[:legend]
clims = get_clims(sp)
@ -1288,7 +1294,8 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
if !isempty(handles)
leg = ax."legend"(handles,
labels,
loc = get(_pyplot_legend_pos, leg, "best"),
loc = py_legend_pos(leg),
bbox_to_anchor = py_legend_bbox(leg),
scatterpoints = 1,
fontsize = py_thickness_scale(plt, sp[:legendfontsize]),
facecolor = py_color(sp[:background_color_legend]),