我有以下图表,其中部分数据被图例遮挡:
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)
是否有任何方法可以将绘图图例完全移动到绘图区域之外,例如在绘图右侧或下方?对于这些堆积的条形图,在情节区域内的传说真的没有好处。到目前为止,我能够提出的唯一解决方案是制作一些"假的"输入数据矩阵中的空行以使用一些零来创建空间,但这似乎有点hacky并且需要一些摆弄以在每次绘制时获得正确数量的额外行:
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中?
答案 0 :(得分:2)
使用布局我可以创建一个解决方法,仅使用图例制作假图。
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)
答案 1 :(得分:1)