juliajulia-plotsmakie.jl

How to fill area between curves in 3D plot in Julia using Makie?


I'm trying to create a 3D fakewaterfall plot using the Makie package in Julia. Therefore i plot multiple spectra, each shifted along the y-axis, in a 3D axis. I got that working, but now i want to fill the area between every spectrum and the x-axis. My minimal working example provides the waterfall plot, but is missing the part on how to fill the area.

In 2D plots i used fill_between!(ax,x,y,0), but i dont know how or if this also works in 3D Plots.

I'm using Julia v1.9.4, Makie v0.21.3 and CairoMakie v0.12.7.

Any guidance would be appreciated! Right now it looks like this, enter image description here but i want it to look like this: enter image description here

using CairoMakie

# Example Data
    spectra = [sin.(1:0.1:10) for _ in 1:10]
    x_values = 1:0.1:10

# Figure
    fig = Figure()

# 3D-Axis
    ax = Axis3(fig[1, 1], title="Waterfallplot", xlabel="X-Axis", ylabel="Y-Axis", zlabel="Z-Axis")

# Plot Data
    for (i, spectrum) in enumerate(spectra)
        y_shift = i  # Shift along y-axis
        points = Point3.(x_values, y_shift,  spectrum)  # Data to Point3
        lines!(ax, points, linewidth=2)  # Plot each spectrum
    end

# Show figure
    fig
# Example Data
    spectra = [sin.(1:0.1:10) for _ in 1:10]
    x_values = 1:0.1:10

# Figure
    fig = Figure()

# 3D-Axis
    ax = Axis3(fig[1, 1], title="Waterfallplot", xlabel="X-Axis", ylabel="Y-Axis", zlabel="Z-Axis")

# Plot Data
    for (i, spectrum) in enumerate(spectra)
        y_shift = i  # Shift along y-axis
        points = Point3.(x_values, y_shift,  spectrum)  # Data to Point3
        lines!(ax, points, linewidth=2)  # Plot each spectrum
    end

# Show figure
    fig# Example Data
    spectra = [sin.(1:0.1:10) for _ in 1:10]
    x_values = 1:0.1:10

# Figure
    fig = Figure()

# 3D-Axis
    ax = Axis3(fig[1, 1], title="Waterfallplot", xlabel="X-Axis", ylabel="Y-Axis", zlabel="Z-Axis")

# Plot Data
    for (i, spectrum) in enumerate(spectra)
        y_shift = i  # Shift along y-axis
        points = Point3.(x_values, y_shift,  spectrum)  # Data to Point3
        lines!(ax, points, linewidth=2)  # Plot each spectrum
    end

# Show figure
    fig# Example Data
    spectra = [sin.(1:0.1:10) for _ in 1:10]
    x_values = 1:0.1:10

# Figure
    fig = Figure()

# 3D-Axis
    ax = Axis3(fig[1, 1], title="Waterfallplot", xlabel="X-Axis", ylabel="Y-Axis", zlabel="Z-Axis")

# Plot Data
    for (i, spectrum) in enumerate(spectra)
        y_shift = i  # Shift along y-axis
        points = Point3.(x_values, y_shift,  spectrum)  # Data to Point3
        lines!(ax, points, linewidth=2)  # Plot each spectrum
    end

# Show figure
    fig

Solution

  • I found a way of doing it: enter image description here

    using CairoMakie
    
    # Example Data
        spectra = [sin.(1:0.1:10) for _ in 1:7]
        x_values = 1:0.1:10
    
    # Figure
        fig = Figure()
    
    # 3D-Axis
        ax = Axis3(fig[1, 1], title="Waterfallplot", xlabel="X-Axis", ylabel="Y-Axis", zlabel="Z-Axis")
    
    # Plot Data
        for i in 7:-1:1
            y_shift = i-1  # Shift along y-axis
            points = Point3.(x_values, y_shift,  spectra[i])  # Data to Point3
            base   = Point3.(x_values, y_shift, minimum(spectra[i]))
            band!(ax, base, points,alpha=0.5,color=Makie.wong_colors()[i])  # Plot each spectrum
            lines!(ax, points, linewidth=2,color=Makie.wong_colors()[i])  # Plot each spectrum
        end
    # Show figure
        fig