Skip to content

Commit

Permalink
modify recipes with default colorscale
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Dec 22, 2022
1 parent 8cd0714 commit 0b4c020
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion precompile/shared-precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end
end

@compile begin
heatmap(1 .+ rand(10, 5), axis = (yscale = log10, xscale=log10))
heatmap(rand(10, 5), axis = (yscale = log10, xscale=log10))
end

@compile begin
Expand Down
8 changes: 4 additions & 4 deletions src/basic_recipes/arrows.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ convert_arguments(::Type{<: Arrows}, x, y, z, u, v, w) = (Point3f.(x, y, z), Vec

function plot!(arrowplot::Arrows{<: Tuple{AbstractVector{<: Point{N, T}}, V}}) where {N, T, V}
@extract arrowplot (
points, directions, colormap, normalize, align,
points, directions, colormap, colorscale, normalize, align,
arrowtail, color, linecolor, linestyle, linewidth, lengthscale,
arrowhead, arrowsize, arrowcolor, quality,
# passthrough
Expand Down Expand Up @@ -160,7 +160,7 @@ function plot!(arrowplot::Arrows{<: Tuple{AbstractVector{<: Point{N, T}}, V}}) w

linesegments!(
arrowplot, headstart,
color = line_c, colormap = colormap, linestyle = linestyle,
color = line_c, colormap = colormap, colorscale = colorscale, linestyle = linestyle,
linewidth = @lift($linewidth === automatic ? 1f0 : $linewidth),
fxaa = fxaa_bool, inspectable = inspectable,
transparency = transparency, visible = visible,
Expand Down Expand Up @@ -208,7 +208,7 @@ function plot!(arrowplot::Arrows{<: Tuple{AbstractVector{<: Point{N, T}}, V}}) w
start, rotations = directions,
marker = @lift(arrow_tail(3, $arrowtail, $quality)),
markersize = msize,
color = line_c, colormap = colormap,
color = line_c, colormap = colormap, colorscale = colorscale,
fxaa = fxaa_bool, ssao = ssao,
diffuse = diffuse,
specular = specular, shininess = shininess, inspectable = inspectable,
Expand All @@ -219,7 +219,7 @@ function plot!(arrowplot::Arrows{<: Tuple{AbstractVector{<: Point{N, T}}, V}}) w
start, rotations = directions,
marker = @lift(arrow_head(3, $arrowhead, $quality)),
markersize = markersize,
color = arrow_c, colormap = colormap,
color = arrow_c, colormap = colormap, colorscale = colorscale,
fxaa = fxaa_bool, ssao = ssao,
diffuse = diffuse,
specular = specular, shininess = shininess, inspectable = inspectable,
Expand Down
3 changes: 2 additions & 1 deletion src/basic_recipes/barplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $(ATTRIBUTES)
offset = 0.0,
color = theme(scene, :patchcolor),
colormap = theme(scene, :colormap),
colorscale = identity,
colorrange = automatic,
lowclip = automatic,
highclip = automatic,
Expand Down Expand Up @@ -254,7 +255,7 @@ function Makie.plot!(p::BarPlot)
p.label_color, p.color_over_background, p.color_over_bar, p.label_formatter, p.label_offset)

poly!(
p, bars, color = p.color, colormap = p.colormap, colorrange = p.colorrange,
p, bars, color = p.color, colormap = p.colormap, colorscale = p.colorscale, colorrange = p.colorrange,
strokewidth = p.strokewidth, strokecolor = p.strokecolor, visible = p.visible,
inspectable = p.inspectable, transparency = p.transparency,
highclip = p.highclip, lowclip = p.lowclip, nan_color = p.nan_color,
Expand Down
1 change: 1 addition & 0 deletions src/basic_recipes/contourf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $(ATTRIBUTES)
levels = 10,
mode = :normal,
colormap = theme(scene, :colormap),
colorscale = identity,
extendlow = nothing,
extendhigh = nothing,
# TODO, Isoband doesn't seem to support nans?
Expand Down
19 changes: 10 additions & 9 deletions src/basic_recipes/contours.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ $(ATTRIBUTES)
default...,
color = nothing,
colormap = theme(scene, :colormap),
colorscale = identity,
colorrange = Makie.automatic,
levels = 5,
linewidth = 1.0,
Expand Down Expand Up @@ -126,19 +127,19 @@ function plot!(plot::Contour{<: Tuple{X, Y, Z, Vol}}) where {X, Y, Z, Vol}
volume!(plot, attr, x, y, z, volume)
end

function color_per_level(color, colormap, colorrange, alpha, levels)
color_per_level(to_color(color), colormap, colorrange, alpha, levels)
function color_per_level(color, colormap, colorscale, colorrange, alpha, levels)
color_per_level(to_color(color), colormap, colorscale, colorrange, alpha, levels)
end

function color_per_level(color::Colorant, colormap, colorrange, alpha, levels)
function color_per_level(color::Colorant, colormap, colorscale, colorrange, alpha, levels)
fill(color, length(levels))
end

function color_per_level(colors::AbstractVector, colormap, colorrange, alpha, levels)
color_per_level(to_colormap(colors), colormap, colorrange, alpha, levels)
function color_per_level(colors::AbstractVector, colormap, colorscale, colorrange, alpha, levels)
color_per_level(to_colormap(colors), colormap, colorscale, colorrange, alpha, levels)
end

function color_per_level(colors::AbstractVector{<: Colorant}, colormap, colorrange, alpha, levels)
function color_per_level(colors::AbstractVector{<: Colorant}, colormap, colorscale, colorrange, alpha, levels)
if length(levels) == length(colors)
return colors
else
Expand All @@ -149,10 +150,10 @@ function color_per_level(colors::AbstractVector{<: Colorant}, colormap, colorran
end
end

function color_per_level(::Nothing, colormap, colorrange, a, levels)
function color_per_level(::Nothing, colormap, colorscale, colorrange, a, levels)
cmap = to_colormap(colormap)
map(levels) do level
c = interpolated_getindex(cmap, level, colorrange)
c = interpolated_getindex(cmap, colorscale(level), colorscale.(colorrange))
RGBAf(color(c), alpha(c) * a)
end
end
Expand All @@ -172,7 +173,7 @@ function plot!(plot::T) where T <: Union{Contour, Contour3d}

replace_automatic!(()-> zrange, plot, :colorrange)

args = @extract plot (color, colormap, colorrange, alpha)
args = @extract plot (color, colormap, colorscale, colorrange, alpha)
level_colors = lift(color_per_level, args..., levels)
result = lift(x, y, z, levels, level_colors) do x, y, z, levels, level_colors
t = eltype(z)
Expand Down
8 changes: 5 additions & 3 deletions src/basic_recipes/error_and_rangebars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $(ATTRIBUTES)
direction = :y,
visible = theme(scene, :visible),
colormap = theme(scene, :colormap),
colorscale = identity,
colorrange = automatic,
inspectable = theme(scene, :inspectable),
transparency = false
Expand Down Expand Up @@ -53,6 +54,7 @@ $(ATTRIBUTES)
direction = :y,
visible = theme(scene, :visible),
colormap = theme(scene, :colormap),
colorscale = identity,
colorrange = automatic,
inspectable = theme(scene, :inspectable),
transparency = false
Expand Down Expand Up @@ -185,7 +187,7 @@ function _plot_bars!(plot, linesegpairs, is_in_y_direction)

f_if(condition, f, arg) = condition ? f(arg) : arg

@extract plot (whiskerwidth, color, linewidth, visible, colormap, colorrange, inspectable, transparency)
@extract plot (whiskerwidth, color, linewidth, visible, "colormap", colorrange, inspectable, transparency)

scene = parent_scene(plot)

Expand Down Expand Up @@ -225,12 +227,12 @@ function _plot_bars!(plot, linesegpairs, is_in_y_direction)

linesegments!(
plot, linesegpairs, color = color, linewidth = linewidth, visible = visible,
colormap = colormap, colorrange = colorrange, inspectable = inspectable,
colormap = colormap, colorscale = colorscale, colorrange = colorrange, inspectable = inspectable,
transparency = transparency
)
linesegments!(
plot, whiskers, color = whiskercolors, linewidth = whiskerlinewidths,
visible = visible, colormap = colormap, colorrange = colorrange,
visible = visible, colormap = colormap, colorscale = colorscale, colorrange = colorrange,
inspectable = inspectable, transparency = transparency
)
plot
Expand Down
3 changes: 3 additions & 0 deletions src/basic_recipes/poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function plot!(plot::Poly{<: Tuple{Union{GeometryBasics.Mesh, GeometryPrimitive}
plot, lift(triangle_mesh, plot[1]),
color = plot[:color],
colormap = plot[:colormap],
colorscale = plot[:colorscale],
colorrange = plot[:colorrange],
lowclip = plot[:lowclip],
highclip = plot[:highclip],
Expand Down Expand Up @@ -91,6 +92,7 @@ function plot!(plot::Poly{<: Tuple{<: Union{Polygon, AbstractVector{<: PolyEleme
shading = plot.shading,
color = plot.color,
colormap = plot.colormap,
colormap = plot.colorscale,
colorrange = plot.colorrange,
lowclip = plot.lowclip,
highclip = plot.highclip,
Expand Down Expand Up @@ -136,6 +138,7 @@ function plot!(plot::Mesh{<: Tuple{<: AbstractVector{P}}}) where P <: Union{Abst
highclip = get(plot, :highclip, automatic),
nan_color = get(plot, :nan_color, :transparent),
colormap = get(plot, :colormap, nothing),
colorscale = get(plot, :colorscale, identity),
colorrange = get(plot, :colorrange, automatic)
)

Expand Down
3 changes: 3 additions & 0 deletions src/basic_recipes/scatterlines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ $(ATTRIBUTES)
Attributes(
color = l_theme.color,
colormap = l_theme.colormap,
colorscale = l_theme.colorscale,
colorrange = get(l_theme.attributes, :colorrange, automatic),
linestyle = l_theme.linestyle,
linewidth = l_theme.linewidth,
Expand Down Expand Up @@ -45,6 +46,7 @@ function plot!(p::Combined{scatterlines, <:NTuple{N, Any}}) where N
linestyle = p.linestyle,
linewidth = p.linewidth,
colormap = p.colormap,
colorscale = p.colorscale,
colorrange = p.colorrange,
inspectable = p.inspectable
)
Expand All @@ -55,6 +57,7 @@ function plot!(p::Combined{scatterlines, <:NTuple{N, Any}}) where N
marker = p.marker,
markersize = p.markersize,
colormap = p.markercolormap,
colorscale = p.colorscale,
colorrange = p.markercolorrange,
inspectable = p.inspectable
)
Expand Down
3 changes: 2 additions & 1 deletion src/basic_recipes/spy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $(ATTRIBUTES)
marker = automatic,
markersize = automatic,
colormap = theme(scene, :colormap),
colorscale = identity,
colorrange = automatic,
framecolor = :black,
framesize = 1,
Expand Down Expand Up @@ -76,7 +77,7 @@ function plot!(p::Spy)
p,
lift(first, xycol), color = lift(last, xycol),
marker = marker, markersize = markersize, colorrange = p.colorrange,
colormap = p.colormap, inspectable = p.inspectable, visible = p.visible
colormap = p.colormap, colorscale = p.colorscale,inspectable = p.inspectable, visible = p.visible
)

lines!(p, rect, color = p.framecolor, linewidth = p.framesize, inspectable = p.inspectable,
Expand Down
4 changes: 4 additions & 0 deletions src/basic_recipes/stem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ $(ATTRIBUTES)
markersize = theme(scene, :markersize),
color = theme(scene, :markercolor),
colormap = theme(scene, :colormap),
colorscale = identity,
colorrange = automatic,
strokecolor = theme(scene, :markerstrokecolor),
strokewidth = theme(scene, :markerstrokewidth),
Expand Down Expand Up @@ -61,6 +62,7 @@ function plot!(s::Stem{<:Tuple{<:AbstractVector{<:Point}}})
linewidth = s.trunkwidth,
color = s.trunkcolor,
colormap = s.trunkcolormap,
colorscale = s.colorscale,
colorrange = s.trunkcolorrange,
visible = s.visible,
linestyle = s.trunklinestyle,
Expand All @@ -69,13 +71,15 @@ function plot!(s::Stem{<:Tuple{<:AbstractVector{<:Point}}})
linewidth = s.stemwidth,
color = s.stemcolor,
colormap = s.stemcolormap,
colorscale = s.colorscale,
colorrange = s.stemcolorrange,
visible = s.visible,
linestyle = s.stemlinestyle,
inspectable = s.inspectable)
scatter!(s, s[1],
color = s.color,
colormap = s.colormap,
colorscale = s.colorscale,
colorrange = s.colorrange,
markersize = s.markersize,
marker = s.marker,
Expand Down
6 changes: 4 additions & 2 deletions src/basic_recipes/streamplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ See the function `Makie.streamplot_impl` for implementation details.
gridsize = (32, 32, 32),
maxsteps = 500,
colormap = theme(scene, :colormap),
colorscale = identity,
colorrange = Makie.automatic,
arrow_size = 15,
arrow_head = automatic,
Expand Down Expand Up @@ -169,7 +170,8 @@ function plot!(p::StreamPlot)
end
lines!(
p,
lift(x->x[3], data), color = lift(last, data), colormap = p.colormap, colorrange = p.colorrange,
lift(x->x[3], data), color = lift(last, data),
colormap = p.colormap, colorscale = p.colorscale, colorrange = p.colorrange,
linestyle = p.linestyle,
linewidth = p.linewidth,
inspectable = p.inspectable,
Expand Down Expand Up @@ -205,7 +207,7 @@ function plot!(p::StreamPlot)
lift(first, data), markersize = p.arrow_size,
marker = @lift(arrow_head(N, $(p.arrow_head), $(p.quality))),
color = lift(x-> x[4], data), rotations = rotations,
colormap = p.colormap, colorrange = p.colorrange,
colormap = p.colormap, colorscale = p.colorscale, colorrange = p.colorrange,
inspectable = p.inspectable, transparency = p.transparency
)
end
3 changes: 3 additions & 0 deletions src/basic_recipes/tricontourf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and vertical positions `ys`.
- `model::Makie.Mat4f` sets a model matrix for the plot. This replaces adjustments made with `translate!`, `rotate!` and `scale!`.
- `color` sets the color of the plot. It can be given as a named color `Symbol` or a `Colors.Colorant`. Transparency can be included either directly as an alpha value in the `Colorant` or as an additional float in a tuple `(color, alpha)`. The color can also be set for each scattered marker by passing a `Vector` of colors or be used to index the `colormap` by passing a `Real` number or `Vector{<: Real}`.
- `colormap::Union{Symbol, Vector{<:Colorant}} = :viridis` sets the colormap from which the band colors are sampled.
- `colorscale::Function = identity` color transform function.
## Attributes
$(ATTRIBUTES)
Expand All @@ -36,6 +37,7 @@ $(ATTRIBUTES)
levels = 10,
mode = :normal,
colormap = theme(scene, :colormap),
colorscale = identity,
extendlow = nothing,
extendhigh = nothing,
nan_color = :transparent,
Expand Down Expand Up @@ -164,6 +166,7 @@ function Makie.plot!(c::Tricontourf{<:Tuple{<:AbstractVector{<:Real},<:AbstractV
poly!(c,
polys,
colormap = c._computed_colormap,
colorscale = c.colorscale,
colorrange = colorrange,
highclip = highcolor,
lowclip = lowcolor,
Expand Down
2 changes: 2 additions & 0 deletions src/makielayout/blocks/colorbar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function Colorbar(fig_or_scene, plot::AbstractPlot; kwargs...)
fig_or_scene;
colormap = plot.colormap,
limits = plot.colorrange,
scale = plot.colorscale,
kwargs...
)
end
Expand Down Expand Up @@ -71,6 +72,7 @@ function Colorbar(fig_or_scene, contourf::Union{Contourf, Tricontourf}; kwargs..
limits = limits,
lowclip = contourf._computed_extendlow,
highclip = contourf._computed_extendhigh,
scale = contourf.colorscale,
kwargs...
)

Expand Down

0 comments on commit 0b4c020

Please sign in to comment.