plot - 在 Makie.jl 中,如何对密度图的范围进行着色?

标签 plot julia makie.jl

如何将该密度图的中间 50% 着色为不同的蓝色(或不同的 alpha 透明度)?

using CairoMakie

f = Figure()
Axis(f[1, 1])

density!(randn(200))

f

enter image description here

最佳答案

这个答案是 @flurble 答案的发展,它完成了寻找正确选项和参数的所有困难。为了使其更可用,我添加了一个辅助函数,并将使用分类颜色图切换为连续颜色图(更易于操作)。代码如下所示:

using CairoMakie, Colors, ColorSchemes, Random, StatsBase

# generate 'square' color gradient
in_out_colorscheme(outcolor, incolor, eps=0.00000001) = 
    cgrad([outcolor, incolor, incolor, outcolor], [0.0,eps,1.0-eps,1.0])

out_blue = HSLA(200,0.9,0.8,0.8)
in_blue = HSLA(200,0.9,0.4,0.8)
blue_in_blue = in_out_colorscheme(out_blue, in_blue);

# generate some data
data = begin
    Random.seed!(14)
    randn(200)
end;

# the region to highlight will be a 50% quantile interval
your_x_min, your_x_max = quantile(data, (0.25,0.75))

begin
    f = Figure()
    ax = Axis(f[1, 1])
    density!(data,
#       strokecolor = out_blue, strokewidth = 2, strokearound = true,
        color=:x,
        colormap=blue_in_blue,
        colorrange=(your_x_min,your_x_max)
    )
    f
end

结果是:

Output chart

PS 奇怪的 begin-end block 源自编写此代码的 Pluto 笔记本单元。

关于plot - 在 Makie.jl 中,如何对密度图的范围进行着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73629698/

相关文章:

julia - 升级 makie 包

ruby - 使用 Ruby 进行科学编程

python - 如何清除 PyQt 中的绘图?

struct - Julia 结构错误 "no method matching iterate"

environment-variables - Julia:未能将 PyCall 配置为使用不同的版本

plot - 如果存在其他绘图元素,则链接 Makie.jl 中的轴

python - Matplotlib 不同大小的子图

r - 如何在 Mac 上的 R 中设置 png 的分辨率

julia - 手动设置 DataFrame Julia 中分组直方图 bin 的 bin 大小