Julia 如何在Plots.jl(GR)中将图例移动到绘图区域之外?
我有以下图表,其中部分数据被图例遮挡:Julia 如何在Plots.jl(GR)中将图例移动到绘图区域之外?,julia,plots.jl,Julia,Plots.jl,我有以下图表,其中部分数据被图例遮挡: using Plots; gr() using StatPlots groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item".*map(string,collect(1:10))) 我可以看到,使用“图例”属性,可以将图例移动到绘图区域内的各个位置,例如: groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item
using Plots; gr()
using StatPlots
groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item".*map(string,collect(1:10)))
我可以看到,使用“图例”属性,可以将图例移动到绘图区域内的各个位置,例如:
groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item".*map(string,collect(1:10)),legend=:bottomright)
是否有任何方法可以将绘图图例完全移到绘图区域之外,例如移到绘图的右侧或下方?对于这种堆叠的条形图,在绘图区域内没有放置图例的好位置。到目前为止,我所能想到的唯一解决方案是在输入数据矩阵中生成一些“假”空行,用一些零来生成空间,但这似乎有点老套,每次绘图时都需要一些修改来获得正确数量的额外行:
groupedbar(vcat(rand(1:100,(10,10)),zeros(3,10)),bar_position=:stack, label="item".*map(string,collect(1:10)),legend=:bottomright)
我可以看到,当时,有人知道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)
现在可以通过以下方式轻松启用: 例如:
plot(rand(10), legend = :outertopleft)
Plotly和PlotlyJS后端支持外部图例(这是它们的默认设置),但我不确定是否有其他后端。您可能应该在GitHub上提交一个问题(在GR.jl或Plots.jl上)。这应该是公认的答案。