Engee 文档

热图

该页面正在翻译中。

heatmap(x, y, matrix)
heatmap(x, y, func)
heatmap(matrix)
heatmap(xvector, yvector, zvector)

将热图绘制为矩形的集合。 xy 可以是长度 ij 哪里 (i,j)尺寸(矩阵),在这种情况下,矩形将像voronoi单元格一样放置在这些网格点周围。 请注意,对于不规则间隔 xy,它们指定的点不在生成的矩形内居中。 xy 也可以是长度 我+1j+1,在这种情况下,它们被解释为矩形的边缘。

矩形的颜色是从 矩阵[i,j]. 第三个参数也可以是一个 功能 (i,j)->v然后在跨越的网格上进行评估 xy.

另一种允许的形式是使用三个向量 xvector,xvector, 伊维克托zvector,zvector. 在这种情况下,假设没有一对元素 xy 存在两次。 从生成的网格中缺少的对将被视为 zvector,zvector 有一个 元件在该位置处。

如果 xy 用矩阵参数省略,它们默认为 x,y=轴(矩阵).

请注意 热图 渲染速度比 图像 所以 图像 应优选大的、规则间隔的网格。

绘图类型

绘图类型别名 热图 功能是 热图.

例子:

两个向量和一个矩阵

在这个例子中, xy 指定放置热图单元格的点。 </无翻译>

using CairoMakie
f = Figure()
ax = Axis(f[1, 1])

centers_x = 1:5
centers_y = 6:10
data = reshape(1:25, 5, 5)

heatmap!(ax, centers_x, centers_y, data)

scatter!(ax, [(x, y) for x in centers_x for y in centers_y], color=:white, strokecolor=:black, strokewidth=1)

f
5ed7cb0

同样的方法适用于不规则间隔的单元格。 请注意矩形如何不在点周围居中,因为边界位于voronoi单元格等相邻点之间。 </无翻译>

using CairoMakie
f = Figure()
ax = Axis(f[1, 1])

centers_x = [1, 2, 4, 7, 11]
centers_y = [6, 7, 9, 12, 16]
data = reshape(1:25, 5, 5)

heatmap!(ax, centers_x, centers_y, data)

scatter!(ax, [(x, y) for x in centers_x for y in centers_y], color=:white, strokecolor=:black, strokewidth=1)
f
4ce014b

如果我们再添加一个元素到 xy,他们现在指定矩形单元格的边缘。 这是一个常规网格: </无翻译>

using CairoMakie
f = Figure()
ax = Axis(f[1, 1])

edges_x = 1:6
edges_y = 7:12
data = reshape(1:25, 5, 5)

热图!(ax,edges_x,edges_y,data)

散开!(ax,[(x,y)for x in edges_x for y in edges_y],color=:white,strokecolor=:black,strokewidth=1)
f
46da8e8

我们也可以用不规则网格做同样的事情: </无翻译>

using CairoMakie
f = Figure()
ax = Axis(f[1, 1])

borders_x = [1, 2, 4, 7, 11, 16]
borders_y = [6, 7, 9, 12, 16, 21]
data = reshape(1:25, 5, 5)

heatmap!(ax, borders_x, borders_y, data)
scatter!(ax, [(x, y) for x in borders_x for y in borders_y], color=:white, strokecolor=:black, strokewidth=1)
f
243eb80

使用 功能 而不是一个 矩阵

当使用 功能 表格的 (i,j)->v 作为 价值 参数,它是在跨越的网格上评估的 xy. </无翻译>

using CairoMakie
function mandelbrot(x, y)
    z = c = x + y*im
    for i in 1:30.0; abs(z) > 2 && return i; z = z^2 + c; end; 0
end

heatmap(-2:0.001:1, -1.1:0.001:1.1, mandelbrot,
    colormap = Reverse(:deep))
952ba6f

三个向量

不能有x和y的重复组合,但允许省略值。 </无翻译>

using CairoMakie
xs = [1, 2, 3, 1, 2, 3, 1, 2, 3]
ys = [1, 1, 1, 2, 2, 2, 3, 3, 3]
zs = [1, 2, 3, 4, 5, 6, 7, 8, NaN]

heatmap(xs, ys, zs)
18af5df

单张热图的彩色条

要获取颜色所代表的比例,请添加colorbar。 Colorbar放置在第一个参数中的图中,并且可以通过将相关的热图传递给它来方便地设置比例和颜色表。 </无翻译>

using CairoMakie
xs = range(0, 2π, length=100)
ys = range(0, 2π, length=100)
zs = [sin(x*y) for x in xs, y in ys]

fig, ax, hm = heatmap(xs, ys, zs)
Colorbar(fig[:, end+1], hm)

fig
c3bc5ce

用于多个热图的Colorbar

当单个图形中有多个热图时,使用单个colorbar表示所有热图可能会很有用。 重要的是,然后有同步的比例和颜色映射的热图和颜色栏。 这是通过显式设置colorrange来完成的,以便它独立于该特定热图显示的数据。

由于下面示例中的热图具有相同的colorrange和colormap,因此它们中的任何一个都可以传递给 颜色栏 为colorbar赋予相同的属性。 或者,可以显式设置colorbar属性。 </无翻译>

using CairoMakie
xs = range(0, 2π, length=100)
ys = range(0, 2π, length=100)
zs1 = [sin(x*y) for x in xs, y in ys]
zs2 = [2sin(x*y) for x in xs, y in ys]

joint_limits = (-2, 2)  # here we pick the limits manually for simplicity instead of computing them

fig, ax1, hm1 = heatmap(xs, ys, zs1,  colorrange = joint_limits)
ax2, hm2 = heatmap(fig[1, end+1], xs, ys, zs2, colorrange = joint_limits)

Colorbar(fig[:, end+1], hm1)                     # These three
Colorbar(fig[:, end+1], hm2)                     # colorbars are
Colorbar(fig[:, end+1], colorrange = joint_limits)  # equivalent

fig
5ce8ab9

使用自定义色阶

可以使用 可逆性,可逆性 类型。 当转换足够简单时(日志, sqrt,sqrt, …​),逆变换被自动推导。 </无翻译>

using CairoMakie
x = 10.0.^(1:0.1:4)
y = 1.0:0.1:5.0
z = broadcast((x, y) -> x - 10, x, y')

scale = ReversibleScale(x -> asinh(x / 2) / log(10), x -> 2sinh(log(10) * x))
fig, ax, hm = heatmap(x, y, z; colorscale = scale, axis = (; xscale = scale))
Colorbar(fig[1, 2], hm)

fig
e03adc0

绘制大型热图

您可以将数据包装到 麦琪再取样器,只为观察区域自动重新采样大热图。 放大时,它会更新重新采样的版本,以最好的保真度显示它。 当任何鼠标或键盘按钮被按下时,它会阻止更新,而不是垃圾邮件,例如WGLMakie与数据更新。 这很适合 轴(图;zoombutton=键盘.left_control). 您可以使用以下方法禁用此行为:

重采样器(数据;update_while_button_pressed=true).

例子::

using Downloads, FileIO, GLMakie
# 30000×22943 image
path = Downloads.download("https://upload.wikimedia.org/wikipedia/commons/7/7e/In_the_Conservatory.jpg")
img = rotr90(load(path))
f, ax, pl = heatmap(Resampler(img); axis=(; aspect=DataAspect()), figure=(;size=size(img)./20))
hidedecorations!(ax)
f

为了获得更好的下采样质量,我们建议使用 麦琪金字塔 (可能会移动到另一个包),它创建了一个简单的高斯金字塔,用于高效和无伪影的向下采样:

pyramid = Makie.Pyramid(img)
fsize = (size(img) ./ 30) .* (1, 2)
fig, ax, pl = heatmap(Resampler(pyramid);
    axis=(; aspect=DataAspect(), title="Pyramid"), figure=(; size=fsize))
hidedecorations!(ax)
ax, pl = heatmap(fig[2, 1], Resampler(img1);
    axis=(; aspect=DataAspect(), title="No Pyramid"))
hidedecorations!(ax)
save("heatmap-pyramid.png", fig)
heatmap pyramid

任何其他数组类型都允许在 再取样器,并且它也可能通过重载来实现它自己的插值策略:

function (array::ArrayType)(xrange::LinRange, yrange::LinRange)
    ...
end

属性

阿尔法

默认值为 1.0

Colormap或color属性的alpha值。 多个阿尔法像在 图(alpha=0.2,颜色=(:红色,0.5),会成倍增加。

夹式飞机

默认值为 自动的

剪辑平面提供了一种在3D空间中进行剪辑的方法。 您可以设置最多8个向量 平面3f 飞机在这里,后面的情节将被裁剪(即变得不可见)。 默认情况下,剪辑平面继承自父绘图或场景。 您可以删除父 夹式飞机 通过传递 平面3f[].

颜色表

默认值为 @继承colormap:viridis

设置为数字采样的颜色表 颜色s. PlotUtils.cgrad(。..), 麦琪反向(any_colormap) 也可以使用,或者来自ColorBrewer或PlotUtils的任何符号。 要查看所有可用的颜色渐变,您可以调用 麦琪可用_gradients().

颜色变化

默认值为 自动的

表示的开始点和结束点的值 颜色表.

色阶;色阶

默认值为 身份认同

的颜色变换功能。 可以是任何函数,但只能与 颜色栏身份认同, 日志, 日志2, 日志10, sqrt,sqrt, 罗吉特, 麦琪伪科学10麦琪符号10.

depth_换档

默认值为 0.0

在所有其他变换之后(即在剪辑空间中)调整绘图的深度值,其中 0<=深度<=1. 这仅适用于GLMakie和WGLMakie,可用于调整渲染顺序(如可调谐透绘)。

外汇管理局

默认值为 真的

调整绘图是否使用fxaa(抗锯齿,仅限GLMakie)渲染。

[医]高

默认值为 自动的

Colorrange上方任何值的颜色。

可检查的

默认值为 @继承inspectable

设置此图是否应由 数据探测仪. 默认值取决于父场景的主题。

检查员-检查员

默认值为 自动的

设置回调函数 (检查员,情节)->。.. 用于清理DataInspector中的自定义指标。

检查员-检查员

默认值为 自动的

设置回调函数 (检查员,情节,索引)->。.. 它取代了默认值 显示_数据 方法。

检查器_label

默认值为 自动的

设置回调函数 (绘图、索引、位置)->字符串 它替换了DataInspector生成的默认标签。

插值,插值

默认值为 错误

设置是否应插值颜色

低频,低频

默认值为 自动的

Colorrange以下任何值的颜色。

模型

默认值为 自动的

为绘图设置模型矩阵。 这将复盖使用 翻译!, 旋转!规模!.

纳米色

默认值为 :透明

NaN值的颜色。

透支

默认值为 错误

控制绘图是否将绘制在其他绘图上。 这具体意味着忽略GL后端中的深度检查

空间

默认值为 :数据

设置包含情节的盒子的变换空间。 见 麦琪空间() 供可能的输入。

ssao

默认值为 错误

调整是否使用ssao(屏幕空间环境光遮蔽)渲染绘图。 请注意,这仅在3D绘图中有意义,并且仅适用于 fxaa=真.

转型

默认值为 :自动

没有可用的文档。

透明度

默认值为 错误

调整情节处理透明度的方式。 在GLMakie 透明度=真 导致使用顺序独立的透明度。

可见

默认值为 真的

控制是否渲染绘图。