gpt4 book ai didi

python - 什么是 R 中不同颜色的 "good"调色板? (或 : can viridis and magma be combined together? )

转载 作者:IT老高 更新时间:2023-10-28 20:32:01 31 4
gpt4 key购买 nike

我有兴趣拥有一个“好”的发散调色板。显然可以只使用红色、白色和蓝色:

img <- function(obj, nam) {
image(1:length(obj), 1, as.matrix(1:length(obj)), col=obj,
main = nam, ylab = "", xaxt = "n", yaxt = "n", bty = "n")
}
rwb <- colorRampPalette(colors = c("red", "white", "blue"))
img(rwb(100), "red-white-blue")

enter image description here

自从我最近爱上了 viridis color palettes ,我是希望将绿色和岩浆结合起来形成如此发散的颜色(当然,色盲的人只会看到颜色的绝对值,但有时也可以)。

当我尝试将 viridis 和 magma 结合起来时,我发现它们不会在同一个地方“结束”(或“开始”),所以我得到了这样的结果(我使用的是 R,但这对于 python 用户):
library(viridis)
img(c(rev(viridis(100, begin = 0)), magma(100, begin = 0)), "magma-viridis")

enter image description here

我们可以看到,当接近于零时,viridis 是紫色的,而岩浆是黑色的。我希望他们都从(或多或少)同一个位置开始,所以我尝试使用 0.3 作为起点:
img(c(rev(viridis(100, begin = 0.3)), magma(100, begin = 0.3)), "-viridis-magma(0.3)")

enter image description here

这确实更好,但我想知道是否有更好的解决方案。

(我也在“标记”python 用户,因为 viridis 最初来自 matplotlib ,所以使用它的人可能知道这样的解决方案)

谢谢!

最佳答案

我找到 Kenneth Moreland's proposal相当有用。它现在已实现为 cool_warmheatmaply :

# install.packages("heatmaply")
img(heatmaply::cool_warm(500), "Cool-warm, (Moreland 2009)")
cool-warm colormap
与内插的 RColorBrewer "RdBu"相比,它在运行时的样子: comparison

关于python - 什么是 R 中不同颜色的 "good"调色板? (或 : can viridis and magma be combined together? ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37482977/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com