You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GLMakie绘图:如何将散点图置于折线图后方

在GLMakie中调整图层顺序:将散点置于折线后方

你当前使用的代码如下:

using GLMakie
x = range(0, 10, length=100)
figure, axis, lineplot = lines(x, sin)
lineplot2 = scatter!(x, cos, color = :red)
figure

这段代码里红色散点遮挡蓝色折线,是因为GLMakie默认按绘制先后顺序堆叠图层,后绘制的元素会显示在上方。

有两种简单方法可以解决这个问题:

方法1:调整绘制顺序

先绘制散点,再绘制折线,让折线覆盖在散点上方:

using GLMakie
x = range(0, 10, length=100)
figure, axis, scatterplot = scatter(x, cos, color = :red)
lineplot = lines!(x, sin)
figure

方法2:设置zorder属性

直接修改元素的层级属性,数值越大的元素显示优先级越高:

using GLMakie
x = range(0, 10, length=100)
figure, axis, lineplot = lines(x, sin)
lineplot2 = scatter!(x, cos, color = :red)
lineplot.zorder = 1  # 让折线层级高于默认的0,显示在散点上方
figure

内容的提问来源于stack exchange,提问作者arnle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 22:27:19