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
相关产品推荐
相关产品推荐

