tricontourf
tricontourf(triangles::Triangulation, zs; kwargs...)
tricontourf(xs, ys, zs; kwargs...)Plots a filled tricontour of the height information in zs at the horizontal positions xs and vertical positions ys. A Triangulation from DelaunayTriangulation.jl can also be provided instead of xs and ys for specifying the triangles, otherwise an unconstrained triangulation of xs and ys is computed.
Attributes
Specific to Tricontourf
levels = 10can be either anIntwhich results in n bands delimited by n+1 equally spaced levels, or it can be anAbstractVector{<:Real}that lists n consecutive edges from low to high, which result in n-1 bands.mode = :normalsets the way in which a vector of levels is interpreted, if it's set to:relative, each number is interpreted as a fraction between the minimum and maximum values ofzs. For example,levels = 0.1:0.1:1.0would exclude the lower 10% of data.extendlow = nothing. This sets the color of an optional additional band fromminimum(zs)to the lowest value inlevels. If it's:auto, the lower end of the colormap is picked and the remaining colors are shifted accordingly. If it's any color representation, this color is used. If it'snothing, no band is added.extendhigh = nothing. This sets the color of an optional additional band from the highest value oflevelstomaximum(zs). If it's:auto, the high end of the colormap is picked and the remaining colors are shifted accordingly. If it's any color representation, this color is used. If it'snothing, no band is added.triangulation = DelaunayTriangulation(). The mode with which the points inxsandysare triangulated. PassingDelaunayTriangulation()performs a Delaunay triangulation. You can also pass a preexisting triangulation as anAbstractMatrix{<:Int}with size (3, n), where each column specifies the vertex indices of one triangle, or as aTriangulationfrom DelaunayTriangulation.jl.
Generic
visible::Bool = truesets whether the plot will be rendered or not.overdraw::Bool = falsesets whether the plot will draw over other plots. This specifically means ignoring depth checks in GL backends.transparency::Bool = falseadjusts how the plot deals with transparency. In GLMakietransparency = trueresults in using Order Independent Transparency.fxaa::Bool = falseadjusts whether the plot is rendered with fxaa (anti-aliasing).inspectable::Bool = truesets whether this plot should be seen byDataInspector.depth_shift::Float32 = 0f0adjusts 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.Mat4fsets a model matrix for the plot. This replaces adjustments made withtranslate!,rotate!andscale!.colorsets the color of the plot. It can be given as a named colorSymbolor aColors.Colorant. Transparency can be included either directly as an alpha value in theColorantor as an additional float in a tuple(color, alpha). The color can also be set for each scattered marker by passing aVectorof colors or be used to index thecolormapby passing aRealnumber orVector{<: Real}.colormap::Union{Symbol, Vector{<:Colorant}} = :viridissets the colormap from which the band colors are sampled.colorscale::Function = identitycolor transform function.
Attributes
Available attributes and their defaults for Combined{Makie.tricontourf} are:
colormap :viridis
colorscale identity
edges "nothing"
extendhigh "nothing"
extendlow "nothing"
inspectable true
levels 10
mode :normal
nan_color :transparent
transparency false
triangulation Makie.DelaunayTriangulation()Examples
using CairoMakie
using Random
Random.seed!(1234)
x = randn(50)
y = randn(50)
z = -sqrt.(x .^ 2 .+ y .^ 2) .+ 0.1 .* randn.()
f, ax, tr = tricontourf(x, y, z)
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
Colorbar(f[1, 2], tr)
fusing CairoMakie
using Random
Random.seed!(1234)
x = randn(200)
y = randn(200)
z = x .* y
f, ax, tr = tricontourf(x, y, z, colormap = :batlow)
scatter!(x, y, color = z, colormap = :batlow, strokewidth = 1, strokecolor = :black)
Colorbar(f[1, 2], tr)
fTriangulation modes
Manual triangulations can be passed as a 3xN matrix of integers, where each column of three integers specifies the indices of the corners of one triangle in the vector of points.
using CairoMakie
using Random
Random.seed!(123)
n = 20
angles = range(0, 2pi, length = n+1)[1:end-1]
x = [cos.(angles); 2 .* cos.(angles .+ pi/n)]
y = [sin.(angles); 2 .* sin.(angles .+ pi/n)]
z = (x .- 0.5).^2 + (y .- 0.5).^2 .+ 0.5.*randn.()
triangulation_inner = reduce(hcat, map(i -> [0, 1, n] .+ i, 1:n))
triangulation_outer = reduce(hcat, map(i -> [n-1, n, 0] .+ i, 1:n))
triangulation = hcat(triangulation_inner, triangulation_outer)
f, ax, _ = tricontourf(x, y, z, triangulation = triangulation,
axis = (; aspect = 1, title = "Manual triangulation"))
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
tricontourf(f[1, 2], x, y, z, triangulation = Makie.DelaunayTriangulation(),
axis = (; aspect = 1, title = "Delaunay triangulation"))
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
fBy default, tricontourf performs unconstrained triangulations. Greater control over the triangulation, such as allowing for enforced boundaries, can be achieved by using DelaunayTriangulation.jl and passing the resulting triangulation as the first argument of tricontourf. For example, the above annulus can also be plotted as follows:
using CairoMakie
using DelaunayTriangulation
using Random
Random.seed!(123)
n = 20
angles = range(0, 2pi, length = n+1)[1:end-1]
x = [cos.(angles); 2 .* cos.(angles .+ pi/n)]
y = [sin.(angles); 2 .* sin.(angles .+ pi/n)]
z = (x .- 0.5).^2 + (y .- 0.5).^2 .+ 0.5.*randn.()
inner = [n:-1:1; n] # clockwise inner
outer = [(n+1):(2n); n+1] # counter-clockwise outer
boundary_nodes = [[outer], [inner]]
points = [x'; y']
tri = triangulate(points; boundary_nodes = boundary_nodes)
f, ax, _ = tricontourf(tri, z;
axis = (; aspect = 1, title = "Constrained triangulation\nvia DelaunayTriangulation.jl"))
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
fBoundary nodes make it possible to support more complicated regions, possibly with holes, than is possible by only providing points themselves.
using CairoMakie
using DelaunayTriangulation
## Start by defining the boundaries, and then convert to the appropriate interface
curve_1 = [
[(0.0, 0.0), (5.0, 0.0), (10.0, 0.0), (15.0, 0.0), (20.0, 0.0), (25.0, 0.0)],
[(25.0, 0.0), (25.0, 5.0), (25.0, 10.0), (25.0, 15.0), (25.0, 20.0), (25.0, 25.0)],
[(25.0, 25.0), (20.0, 25.0), (15.0, 25.0), (10.0, 25.0), (5.0, 25.0), (0.0, 25.0)],
[(0.0, 25.0), (0.0, 20.0), (0.0, 15.0), (0.0, 10.0), (0.0, 5.0), (0.0, 0.0)]
] # outer-most boundary: counter-clockwise
curve_2 = [
[(4.0, 6.0), (4.0, 14.0), (4.0, 20.0), (18.0, 20.0), (20.0, 20.0)],
[(20.0, 20.0), (20.0, 16.0), (20.0, 12.0), (20.0, 8.0), (20.0, 4.0)],
[(20.0, 4.0), (16.0, 4.0), (12.0, 4.0), (8.0, 4.0), (4.0, 4.0), (4.0, 6.0)]
] # inner boundary: clockwise
curve_3 = [
[(12.906, 10.912), (16.0, 12.0), (16.16, 14.46), (16.29, 17.06),
(13.13, 16.86), (8.92, 16.4), (8.8, 10.9), (12.906, 10.912)]
] # this is inside curve_2, so it's counter-clockwise
curves = [curve_1, curve_2, curve_3]
points = [
(3.0, 23.0), (9.0, 24.0), (9.2, 22.0), (14.8, 22.8), (16.0, 22.0),
(23.0, 23.0), (22.6, 19.0), (23.8, 17.8), (22.0, 14.0), (22.0, 11.0),
(24.0, 6.0), (23.0, 2.0), (19.0, 1.0), (16.0, 3.0), (10.0, 1.0), (11.0, 3.0),
(6.0, 2.0), (6.2, 3.0), (2.0, 3.0), (2.6, 6.2), (2.0, 8.0), (2.0, 11.0),
(5.0, 12.0), (2.0, 17.0), (3.0, 19.0), (6.0, 18.0), (6.5, 14.5),
(13.0, 19.0), (13.0, 12.0), (16.0, 8.0), (9.8, 8.0), (7.5, 6.0),
(12.0, 13.0), (19.0, 15.0)
]
boundary_nodes, points = convert_boundary_points_to_indices(curves; existing_points=points)
edges = Set(((1, 19), (19, 12), (46, 4), (45, 12)))
## Extract the x, y
tri = triangulate(points; boundary_nodes = boundary_nodes, edges = edges, check_arguments = false)
z = [(x - 1) * (y + 1) for (x, y) in each_point(tri)] # note that each_point preserves the index order
f, ax, _ = tricontourf(tri, z, levels = 30; axis = (; aspect = 1))
fusing CairoMakie
using DelaunayTriangulation
using Random
Random.seed!(1234)
θ = [LinRange(0, 2π * (1 - 1/19), 20); 0]
xy = Vector{Vector{Vector{NTuple{2,Float64}}}}()
cx = [0.0, 3.0]
for i in 1:2
push!(xy, [[(cx[i] + cos(θ), sin(θ)) for θ in θ]])
push!(xy, [[(cx[i] + 0.5cos(θ), 0.5sin(θ)) for θ in reverse(θ)]])
end
boundary_nodes, points = convert_boundary_points_to_indices(xy)
tri = triangulate(points; boundary_nodes=boundary_nodes, check_arguments=false)
z = [(x - 3/2)^2 + y^2 for (x, y) in each_point(tri)] # note that each_point preserves the index order
f, ax, tr = tricontourf(tri, z, colormap = :matter)
fRelative mode
Sometimes it's beneficial to drop one part of the range of values, usually towards the outer boundary. Rather than specifying the levels to include manually, you can set the mode attribute to :relative and specify the levels from 0 to 1, relative to the current minimum and maximum value.
using CairoMakie
using Random
Random.seed!(1234)
x = randn(50)
y = randn(50)
z = -sqrt.(x .^ 2 .+ y .^ 2) .+ 0.1 .* randn.()
f, ax, tr = tricontourf(x, y, z, mode = :relative, levels = 0.2:0.1:1)
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
Colorbar(f[1, 2], tr)
fThese docs were autogenerated using Makie: v0.19.12, GLMakie: v0.8.12, CairoMakie: v0.10.12, WGLMakie: v0.8.16