gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:55:10 27 4
gpt4 key购买 nike

我有以下图,其中部分数据被图例遮挡:

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

stacked bar plot

我可以看到使用“legend”属性,可以将图例移动到绘图区域内的各个位置,例如:
groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item".*map(string,collect(1:10)),legend=:bottomright)

stacked bar plot with legend at bottom right

有没有办法将绘图图例完全移动到绘图区域之外,例如在绘图的右侧或下方?对于这些类型的堆积条形图,图区域内的图例确实没有什么好地方。到目前为止,我能想出的唯一解决方案是在输入数据矩阵中创建一些“假”空行,以腾出一些零的空间,但这似乎有点笨拙,需要一些摆弄才能得到正确的结果每次绘制时的额外行数:
groupedbar(vcat(rand(1:100,(10,10)),zeros(3,10)),bar_position=:stack, label="item".*map(string,collect(1:10)),legend=:bottomright)

stacked bar plot with legend placed in extra white space

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

最佳答案

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

例子:

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

enter image description here

关于julia - 如何将图例移动到 Plots.jl (GR) 中的绘图区域之外?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45097631/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com