如何绘制a'比例图形'在朱莉娅?

发布于 2025-01-19 21:43:30 字数 196 浏览 3 评论 0原文

这是我正在寻找的示例:

示例比例图

我查看了文档中的所有示例,但找不到类似的图表。任何帮助将不胜感激。

Here is an example of what I am looking for:

example proportion plot

I've looked at all of the examples in the documentation and could not find a similar graph. Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小嗲 2025-01-26 21:43:30

这是一种方法:

using Plots

@userplot StackedArea

# a simple "recipe" for Plots.jl to get stacked area plots
# usage: stackedarea(xvector, datamatrix, plotsoptions)
@recipe function f(pc::StackedArea)
    x, y = pc.args
    n = length(x)
    y = cumsum(y, dims=2)
    seriestype := :shape

    # create a filled polygon for each item
    for c=1:size(y,2)
        sx = vcat(x, reverse(x))
        sy = vcat(y[:,c], c==1 ? zeros(n) : reverse(y[:,c-1]))
        @series (sx, sy)
    end
end

a = [1,1,1,1.5,2,3]
b = [0.5,0.6,0.4,0.3,0.3,0.2]
c = [2,1.8,2.2,3.3,2.5,1.8]
sNames = ["a","b","c"]

来源: https://discourse.julialang.org/t/how-to-to-plot-a-simple-stacked-area-chart/21351/2

Here's a way:

using Plots

@userplot StackedArea

# a simple "recipe" for Plots.jl to get stacked area plots
# usage: stackedarea(xvector, datamatrix, plotsoptions)
@recipe function f(pc::StackedArea)
    x, y = pc.args
    n = length(x)
    y = cumsum(y, dims=2)
    seriestype := :shape

    # create a filled polygon for each item
    for c=1:size(y,2)
        sx = vcat(x, reverse(x))
        sy = vcat(y[:,c], c==1 ? zeros(n) : reverse(y[:,c-1]))
        @series (sx, sy)
    end
end

a = [1,1,1,1.5,2,3]
b = [0.5,0.6,0.4,0.3,0.3,0.2]
c = [2,1.8,2.2,3.3,2.5,1.8]
sNames = ["a","b","c"]

enter image description here

source: https://discourse.julialang.org/t/how-to-plot-a-simple-stacked-area-chart/21351/2

醉生梦死 2025-01-26 21:43:30

以下@sanidhya-singh的链接还提供了一个内置解决方案:

julia> areaplot(1:3, [1 2 3; 7 8 9; 4 5 6], seriescolor = [:red :green :blue], fillalpha = [0.2 0.3 0.4])

它提供了

在此处输入图像描述

也许值得添加到文档中!


[编辑] 此示例已添加到 Plots.jl 文档

Following @sanidhya-singh's link also gives a built-in solution:

julia> areaplot(1:3, [1 2 3; 7 8 9; 4 5 6], seriescolor = [:red :green :blue], fillalpha = [0.2 0.3 0.4])

which gives

enter image description here

Maybe worth adding to the docs though!


[EDIT] This example has been added to the Plots.jl docs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文