如何将图例移动到 Plots.jl (GR) 中的绘图区域之外?

How to move the legend to outside the plotting area in Plots.jl (GR)?

我有以下情节,其中部分数据被图例遮盖了:

using Plots; gr()
using StatPlots
groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item".*map(string,collect(1:10)))

我可以看到使用 "legend" 属性,可以将图例移动到绘图区域内的各个位置,例如:

groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item".*map(string,collect(1:10)),legend=:bottomright)

有什么方法可以将绘图图例完全移到绘图区域之外,例如移到绘图的右侧或下方?对于这些类型的堆叠条形图,绘图区域内的图例确实没有什么好地方。到目前为止,我能想到的唯一解决方案是在输入数据矩阵中创建一些 "fake" 空行,使 space 带有一些零,但这似乎有点老套,需要每次绘制时都需要一些小动作来获得正确数量的额外行:

groupedbar(vcat(rand(1:100,(10,10)),zeros(3,10)),bar_position=:stack, label="item".*map(string,collect(1:10)),legend=:bottomright)

我看到有 some kind of a solution proposed for pyplot,有人知道 GR 后端的类似解决方案吗?我能想到的另一种解决方案 - 有没有办法将图例本身保存到不同的文件中,然后我可以将它们放回到 Inkscape 中?

使用布局,我可以创建一个仅使用图例制作假图的解决方法。

using Plots
gr()
l = @layout [a{0.001h}; b c{0.13w}]

values = rand(1:100,(10,10))

p1 = groupedbar(values,bar_position=:stack, legend=:none)
p2 = groupedbar(values,bar_position=:stack, label="item".*map(string,collect(1:10)), grid=false, xlims=(20,3), showaxis=false)


p0=plot(title="Title",grid=false, showaxis=false)

plot(p0,p1,p2,layout=l)

现在可以通过 Plots.jl 轻松启用:

示例:

plot(rand(10), legend = :outertopleft)