diff --git a/src/basic_recipes/basic_recipes.jl b/src/basic_recipes/basic_recipes.jl index cabba5b07..6d4bec2a7 100644 --- a/src/basic_recipes/basic_recipes.jl +++ b/src/basic_recipes/basic_recipes.jl @@ -779,7 +779,7 @@ function plot!(plot::T) where T <: Union{Contour, Contour3d} end function data_limits(x::Contour{<: Tuple{X, Y, Z}}) where {X, Y, Z} - xyz_boundingbox(transform_func(x), to_value.((x[1], x[2]))...) + return xyz_boundingbox(transform_func(x), to_value.((x[1], x[2]))...) end """ diff --git a/src/conversions.jl b/src/conversions.jl index 2885a75ca..fd715ae32 100644 --- a/src/conversions.jl +++ b/src/conversions.jl @@ -267,6 +267,7 @@ float32type(::Type{<: Colorant}) = RGBA{Float32} float32type(x::AbstractArray{T}) where T = float32type(T) float32type(x::T) where T = float32type(T) el32convert(x::AbstractArray) = elconvert(float32type(x), x) +el32convert(x::Observable) = lift(el32convert, x) el32convert(x) = convert(float32type(x), x) function el32convert(x::AbstractArray{T, N}) where {T<:Union{Missing, <: Number}, N} @@ -551,6 +552,11 @@ end # Attribute conversions # ################################################################################ +convert_attribute(p, ::key"highclip") = to_color(p) +convert_attribute(p::Nothing, ::key"highclip") = p +convert_attribute(p, ::key"lowclip") = to_color(p) +convert_attribute(p::Nothing, ::key"lowclip") = p +convert_attribute(p, ::key"nan_color") = to_color(p) struct Palette{N} colors::SArray{Tuple{N},RGBA{Float32},1,N} diff --git a/src/interfaces.jl b/src/interfaces.jl index 9cfc132c6..8e76bb13e 100644 --- a/src/interfaces.jl +++ b/src/interfaces.jl @@ -52,6 +52,8 @@ $(ATTRIBUTES) colormap = [:black, :white], interpolate = true, fxaa = false, + lowclip = nothing, + highclip = nothing, ) end @@ -120,8 +122,9 @@ $(ATTRIBUTES) color = nothing, colormap = :viridis, shading = true, - interpolate = true, fxaa = true, + lowclip = nothing, + highclip = nothing, ) end @@ -292,6 +295,7 @@ function calculated_attributes!(::Type{<: Union{Heatmap, Image}}, plot) plot[:color] = plot[3] color_and_colormap!(plot) end + function calculated_attributes!(::Type{<: Surface}, plot) colors = plot[3] if haskey(plot, :color) diff --git a/test/simple.jl b/test/simple.jl index e15d3960c..17db3e3f8 100644 --- a/test/simple.jl +++ b/test/simple.jl @@ -2,10 +2,28 @@ using AbstractPlotting using GLMakie using GeometryBasics using Observables -using FileIO using GeometryBasics: Pyramid using PlotUtils +using MeshIO, FileIO + +## Some helpers +data_2d = AbstractPlotting.peaks() +args_2d = (-10..10, -10..10, data_2d) + +function n_times(f, n=10, interval=0.05) + obs = Observable(f(1)) + @async for i in 2:n + try + obs[] = f(i) + sleep(interval) + catch e + @warn "Error!" exception=CapturedException(e, Base.catch_backtrace()) + end + end + return obs +end +## Scatter scatter(1:4, color=:red) scatter(1:4, marker='☼') scatter(1:4, marker=['☼', '◒', '◑', '◐']) @@ -14,7 +32,7 @@ scatter(1:4, marker=rand(RGBf0, 10, 10), markersize=20px) |> display # TODO rotation with markersize=px scatter(1:4, marker='▲', markersize=0.3, rotations=LinRange(0, pi, 4)) |> display -# Meshscatter +## Meshscatter meshscatter(1:4, color=1:4) |> display meshscatter(1:4, color=rand(RGBAf0, 4)) @@ -23,7 +41,7 @@ meshscatter(1:4, color=:red) meshscatter(rand(Point3f0, 10), color=rand(RGBf0, 10)) meshscatter(rand(Point3f0, 10), marker=Pyramid(Point3f0(0), 1f0, 1f0)) |> display -# Lines +## Lines positions = Point2f0.([1:4; NaN; 1:4], [1:4; NaN; 2:5]) lines(positions) lines(positions, linestyle=:dot) @@ -31,7 +49,7 @@ lines(positions, linestyle=[0.0, 1.0, 2.0, 3.0, 4.0]) lines(positions, color=1:9) lines(positions, color=rand(RGBf0, 9), linewidth=4) -# Linesegments +## Linesegments linesegments(1:4) linesegments(1:4, linestyle=:dot) linesegments(1:4, linestyle=[0.0, 1.0, 2.0, 3.0, 4.0]) @@ -39,21 +57,21 @@ linesegments(1:4, color=1:4) linesegments(1:4, color=rand(RGBf0, 4), linewidth=4) -# Surface -data = AbstractPlotting.peaks() -surface(-10..10, -10..10, data) -surface(-10..10, -10..10, data, color=rand(size(data)...)) |> display -surface(-10..10, -10..10, data, color=rand(RGBf0, size(data)...)) -surface(-10..10, -10..10, data, colormap=:magma, colorrange=(0.0, 2.0)) +## Surface +surface(args_2d...) +surface(args_2d..., color=rand(size(data_2d)...)) +surface(args_2d..., color=rand(RGBf0, size(data_2d)...)) +surface(args_2d..., colormap=:magma, colorrange=(-3.0, 4.0)) +surface(args_2d..., shading=false); wireframe!(args_2d..., linewidth=0.5) -# Polygons +## Polygons poly(decompose(Point2f0, Circle(Point2f0(0), 1f0))) -# Image like! +## Image like! image(rand(10, 10)) heatmap(rand(10, 10)) -# Volumes +## Volumes volume(rand(4, 4, 4), isovalue=0.5, isorange=0.01, algorithm=:iso) |> display volume(rand(4, 4, 4), algorithm=:mip) volume(rand(4, 4, 4), algorithm=:absorption) @@ -62,8 +80,7 @@ volume(rand(4, 4, 4), algorithm=Int32(5)) |> display volume(rand(RGBAf0, 4, 4, 4), algorithm=:absorptionrgba) contour(rand(4, 4, 4)) |> display -# Meshes -using MeshIO, FileIO +## Meshes cat = load(GLMakie.assetpath("cat.obj")) tex = load(GLMakie.assetpath("diffusemap.tga")); scren = mesh(cat, color=tex) @@ -74,7 +91,7 @@ m = mesh([(0.0, 0.0), (0.5, 1.0), (1.0, 0.0)], color = [:red, :green, :blue], meshes = GeometryBasics.normal_mesh.([Sphere(Point3f0(0.5), 1), Rect(Vec3f0(1, 0, 0), Vec3f0(1))]) mesh(meshes, color=[1, 2]) -# Axis +## Axis scene = lines(IRect(Vec2f0(0), Vec2f0(1))) axis = scene[Axis] axis.ticks.ranges = ([0.1, 0.2, 0.9], [0.1, 0.2, 0.9]) @@ -82,29 +99,20 @@ axis.ticks.labels = (["😸", "♡", "𝕴"], ["β ÷ δ", "22", "≙"]) scene -# Text +## Text x = text("heyllo") |> display -# Gradients -data = ((x, y) -> x^2 + y^2).(1:100, (1:100)') -heatmap(data; colormap=cgrad(:RdYlBu; categorical=true), interpolate=true) -extrema(data) -heatmap(data; interpolate=true, colorrange=(-6.0, 7.0), highclip=:black, lowclip=:pink) +## Colormaps +cmap = cgrad(:RdYlBu; categorical=true); +heatmap(args_2d...; colormap=cgrad(:RdYlBu; categorical=true), interpolate=true) -# Animations -function n_times(f, n=10, interval=0.05) - obs = Observable(f(1)) - @async for i in 2:n - try - obs[] = f(i) - sleep(interval) - catch e - @warn "Error!" exception=CapturedException(e, Base.catch_backtrace()) - end - end - return obs -end +image(args_2d...; colormap=cgrad(:RdYlBu; categorical=true), interpolate=true) + +s = heatmap(args_2d...; colorrange=(-4.0, 3.0), colormap=cmap, highclip=:green, lowclip=:pink, interpolate=true) +surface(args_2d...; colorrange=(-4.0, 3.0), highclip=:green, lowclip=:pink) + +## Animations annotations(n_times(i-> map(j-> ("$j", Point2f0(j*30, 0)), 1:i)), textsize=20, limits=FRect2D(30, 0, 320, 50)) scatter(n_times(i-> Point2f0.((1:i).*30, 0)), limits=FRect2D(30, 0, 320, 50), markersize=20px) @@ -136,8 +144,7 @@ lp = map(radius, theta, phi) do r, theta, phi end scene = Scene() -contour!(scene, 0..1, 0..1, 0..1, rand(10, 10, 10), levels = 2; -ambient = la, diffuse = ld, specular = ls, shininess = shininess,lightposition = lp) +surface!(scene, args_2d...; ambient = la, diffuse = ld, specular = ls, shininess = shininess,lightposition = lp) scatter!(scene, map(v -> [v], lp), color=:yellow, markersize=0.2f0) vbox(hbox(s4, s3, s2, s1, s7, s6, s5), scene) |> display @@ -150,8 +157,12 @@ lines!(1:4, color=rand(RGBf0, 4)) |> display # Views - x = Point2f0[(1, 1), (2, 2), (3, 2), (4, 4)] points = connect(x, LineFace{Int}[(1, 2), (2, 3), (3, 4)]) linesegments(points) scatter(x) +p4 = heatmap(rand(100, 100)) + +# Interpolation +heatmap(data_2d, interpolate=true) +image(data_2d, interpolate=false)