Skip to content

Commit

Permalink
added example of contourf and surface to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
behinger committed Sep 18, 2024
1 parent b8a74c0 commit c33146e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
22 changes: 22 additions & 0 deletions docs/src/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,25 @@ TopoPlots.topoplot(
label_scatter=(; strokewidth=2),
contours=(linewidth=2, color=:white))
```


## Different plotfunctions

It is possible to exchange the plotting function, from `heatmap!` to `contourf!` or `surface!`. Due to different keyword arguments, one needs to filter which keywords are passed to the plotting function manually.

```@example 1
f = Figure()
TopoPlots.topoplot(f[1,1],
rand(10), rand(Point2f, 10),
axis=(; aspect=DataAspect()),
plotfnc! = contourf!, plotfnc_kwargs_filter=[:colormap])
TopoPlots.topoplot(f[1,2],
rand(10), rand(Point2f, 10),
axis=(; aspect=DataAspect()),
plotfnc! = surface!) # surface can take all default kwargs similar to heatmap!
f
```
11 changes: 8 additions & 3 deletions src/core-recipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
labels = nothing,
label_text = false,
label_scatter = false,
contours = false
contours = false,
plotfnc! = heatmap!,
plotfnc_kwargs_filter= [:colorrange, :colormap, :interpolate],
)
end

Expand All @@ -39,6 +41,8 @@ Creates an irregular interpolation for each `data[i]` point at `positions[i]`.
* true: add point for each position with default attributes
* NamedTuple: Attributes get passed to the Makie.scatter! call.
* `markersize = 5`: size of the points defined by positions, shortcut for label_scatter=(markersize=5,)
* `plotfnc! = heatmap!`: function to use for plotting the interpolation
* `plotfnc_kwargs_filter = [:colorrange, :colormap, :interpolate]`: different `plotfnc` support different kwargs, this array contains the keys to filter the full list which is [:colorrange, :colormap, :interpolate]
* `contours = false`:
* true: add scatter point for each position
Expand Down Expand Up @@ -116,8 +120,9 @@ function Makie.plot!(p::TopoPlot)
# z[mask] .= NaN
return z
end

heatmap!(p, xg, yg, data, colormap=p.colormap, colorrange=colorrange, interpolate=true)
kwargs_all = Dict(:colorrange => colorrange, :colormap => p.colormap, :interpolate => true)

p.plotfnc![](p, xg, yg, data; (p.plotfnc_kwargs_filter[].=>getindex.(Ref(kwargs_all),p.plotfnc_kwargs_filter[]))...)
contours = to_value(p.contours)
attributes = @plot_or_defaults contours Attributes(color=(:black, 0.5), linestyle=:dot, levels=6)
if !isnothing(attributes) && !(p.interpolation[] isa NullInterpolator)
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,10 @@ begin
lines!(ax, rect_extended, color=:red)
@test_figure("test-extrapolate-data-circle", f)
end

let
data, positions = TopoPlots.example_data()
f, ax, pl = topoplot(1:10,positions[1:10];plotfnc! = contourf!,plotfnc_kwargs_filter=[:colormap])
f, ax, pl = topoplot(1:10,positions[1:10];plotfnc! = (args...;kwargs...)->heatmap!(args...;alpha=0.3,kwargs...))
#@test_figure("ClaughTochter", f)
end

0 comments on commit c33146e

Please sign in to comment.