heatmap
heatmap(x, y, values)
heatmap(values)
Plots a heatmap as an image on
x, y
(defaults to interpretation as dimensions).
Attributes
Specific to
Heatmap
-
lowclip::Union{Nothing, Symbol, <:Colorant} = nothing
sets a color for any value below the colorrange. -
highclip::Union{Nothing, Symbol, <:Colorant} = nothing
sets a color for any value above the colorrange. -
interpolate::Bool = false
sets whether colors should be interpolated.
Generic
-
visible::Bool = true
sets whether the plot will be rendered or not. -
overdraw::Bool = false
sets whether the plot will draw over other plots. This specifically means ignoring depth checks in GL backends. -
transparency::Bool = false
adjusts how the plot deals with transparency. In GLMakietransparency = true
results in using Order Independent Transparency. -
fxaa::Bool = true
adjusts whether the plot is rendered with fxaa (anti-aliasing). -
inspectable::Bool = true
sets whether this plot should be seen byDataInspector
. -
depth_shift::Float32 = 0f0
adjusts the depth value of a plot after all other transformations, i.e. in clip space, where0 <= depth <= 1
. This only applies to GLMakie and WGLMakie and can be used to adjust render order (like a tunable overdraw). -
model::Makie.Mat4f
sets a model matrix for the plot. This replaces adjustments made withtranslate!
,rotate!
andscale!
. -
color
is set by the plot. -
colormap::Union{Symbol, Vector{<:Colorant}} = :viridis
sets the colormap that is sampled for numericcolor
s. -
colorrange::Tuple{<:Real, <:Real}
sets the values representing the start and end points ofcolormap
. -
nan_color::Union{Symbol, <:Colorant} = RGBAf(0,0,0,0)
sets a replacement color forcolor = NaN
. -
space::Symbol = :data
sets the transformation space for the position of the heatmap. SeeMakie.spaces()
for possible inputs.
Examples
Two vectors and a matrix
using CairoMakie
xs = range(0, 10, length = 25)
ys = range(0, 15, length = 25)
zs = [cos(x) * sin(y) for x in xs, y in ys]
heatmap(xs, ys, zs)
Two ranges and a function
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.1:1, -1.1:0.1:1.1, mandelbrot,
colormap = Reverse(:deep))
Three vectors
There must be no duplicate combinations of x and y, but it is allowed to leave out values.
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)
Colorbar for single heatmap
To get a scale for what the colors represent, add a colorbar. The colorbar is placed within the figure in the first argument, and the scale and colormap can be conveniently set by passing the relevant heatmap to it.
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
Colorbar for multiple heatmaps
When there are several heatmaps in a single figure, it can be useful to have a single colorbar represent all of them. It is important to then have synchronized scales and colormaps for the heatmaps and colorbar. This is done by setting the colorrange explicitly, so that it is independent of the data shown by that particular heatmap.
Since the heatmaps in the example below have the same colorrange and colormap, any of them can be passed to
Colorbar
to give the colorbar the same attributes. Alternativly, the colorbar attributes can be set explicitly.
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
These docs were autogenerated using Makie: v0.18.4, GLMakie: v0.7.4, CairoMakie: v0.9.4, WGLMakie: v0.7.4