MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.41k stars 312 forks source link

Stack lines/band #4315

Open theogf opened 2 months ago

theogf commented 2 months ago

Feature description

Given a collection of N vectors (in the form of a matrix or a vector of vector), plot N lines computed as the cumulated sum (cumsum). Right now this could be done with

A = rand(3, 10)
cum_A = cumsum(A; dims = 1)
x = 1:10
for i in 1:size(A, 2)
   lines!(ax, x, cum_A[i, :])
end

Additionally it would be great if one could fill in between the lines.

For plot types, please add an image of how it should look like

Here is an example of what one obtain using git-of-theseus

image

asinghvi17 commented 1 month ago

Looks like this could be done by a vector of constructed polygons sent to poly, or potentially using band with per vertex colors for efficiency. But I like the simplicity of poly and we can always pass a vector of preconstructed meshes.. @theogf what would your ideal API look like?

I was imagining something like stackedarea(xs, ys::Union{Vector{Vector{Real}}, Matrix{Real}}; color = ..., ...). The x-axis must be shared across the line vectors.

One thing I'm not sure of is how the example plot you have might work in this type of API - maybe setting each y-value before the area is supposed to start to 0? Not sure if that would map well to a polygon.

The polygon could be created by simply appending points[series_i] and reverse(points[series_i-1]) or so, and it would have to be closed such that the last point of the vector of points is equal to the first point.