Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow scalar number colors for legend entries #3587

Merged
merged 4 commits into from
Feb 1, 2024

Conversation

jkrumbiegel
Copy link
Member

@jkrumbiegel jkrumbiegel commented Feb 1, 2024

Description

Fixes #3551, #3532, #1905,

Picks up colormap and colorrange settings from plot objects so that a number color does not error anymore when passed down to the plotting primitives of the legend entries.

f = Figure()
ax = Axis(f[1, 1])
for i in 1:3
    lines!(ax, (1:3) .+ i, color = i, colorrange = (0, 4), colormap = :Blues, label = "Line $i", linewidth = 3)
end
for i in 1:3
    scatter!(ax, (1:3) .+ i .+ 3, color = i, colorrange = (0, 4), colormap = :plasma, label = "Scatter $i", markersize = 15)
end
for i in 1:3
    barplot!(ax, (1:3) .+ i .+ 8, fillto = (1:3) .+ i .+ 7.5, color = i, colorrange = (0, 4), colormap = :tab10, label = "Barplot $i")
end
for i in 1:3
    poly!(ax, [Rect2f((j, i .+ 12 + j), (0.5, 0.5)) for j in 1:3], color = i, colorrange = (0, 4), colormap = :heat, label = "Poly $i")
end
Legend(f[1, 2], ax)
f
image

Type of change

Delete options that do not apply:

  • New feature (non-breaking change which adds functionality)

Checklist

  • Added an entry in NEWS.md (for new features and breaking changes)
  • Added reference image tests for new plotting functions, recipes, visual options, etc.

@MakieBot
Copy link
Collaborator

MakieBot commented Feb 1, 2024

Compile Times benchmark

Note, that these numbers may fluctuate on the CI servers, so take them with a grain of salt. All benchmark results are based on the mean time and negative percent mean faster than the base branch. Note, that GLMakie + WGLMakie run on an emulated GPU, so the runtime benchmark is much slower. Results are from running:

using_time = @ctime using Backend
# Compile time
create_time = @ctime fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @ctime Makie.colorbuffer(display(fig))
# Runtime
create_time = @benchmark fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @benchmark Makie.colorbuffer(fig)
using create display create display
GLMakie 3.47s (3.45, 3.53) 0.03+- 391.56ms (381.01, 399.42) 6.02+- 470.51ms (465.99, 477.89) 4.74+- 7.36ms (7.27, 7.43) 0.06+- 25.54ms (25.45, 25.73) 0.10+-
master 3.46s (3.43, 3.52) 0.03+- 396.12ms (386.65, 408.16) 10.18+- 474.65ms (464.88, 514.12) 17.52+- 7.26ms (7.20, 7.33) 0.05+- 25.42ms (25.37, 25.50) 0.04+-
evaluation 1.00x invariant, 0.01s (0.27d, 0.62p, 0.03std) 1.01x invariant, -4.56ms (-0.55d, 0.33p, 8.10std) 1.01x invariant, -4.14ms (-0.32d, 0.57p, 11.13std) 0.99x slower X, 0.09ms (1.72d, 0.01p, 0.05std) 1.00x slower X, 0.11ms (1.53d, 0.02p, 0.07std)
CairoMakie 3.07s (3.00, 3.14) 0.05+- 326.95ms (313.59, 366.12) 18.14+- 141.78ms (137.83, 151.82) 4.80+- 7.33ms (7.14, 7.48) 0.13+- 603.99μs (598.96, 610.54) 4.90+-
master 3.07s (3.02, 3.14) 0.04+- 325.98ms (318.06, 340.33) 8.04+- 142.21ms (138.95, 148.26) 3.28+- 7.39ms (7.11, 7.66) 0.22+- 608.00μs (598.44, 616.91) 5.91+-
evaluation 1.00x invariant, -0.01s (-0.12d, 0.82p, 0.04std) 1.00x invariant, 0.97ms (0.07d, 0.90p, 13.09std) 1.00x invariant, -0.43ms (-0.11d, 0.85p, 4.04std) 1.01x invariant, -0.06ms (-0.35d, 0.53p, 0.17std) 1.01x invariant, -4.01μs (-0.74d, 0.19p, 5.40std)
WGLMakie 3.73s (3.69, 3.78) 0.03+- 321.33ms (316.87, 324.09) 2.52+- 8.90s (8.80, 8.96) 0.05+- 9.25ms (9.16, 9.41) 0.09+- 73.63ms (67.36, 85.45) 7.10+-
master 3.71s (3.69, 3.75) 0.02+- 325.43ms (318.22, 339.40) 8.32+- 8.86s (8.81, 8.89) 0.03+- 9.28ms (9.06, 9.77) 0.23+- 73.55ms (68.66, 81.59) 5.48+-
evaluation 0.99x invariant, 0.02s (0.82d, 0.15p, 0.03std) 1.01x invariant, -4.1ms (-0.67d, 0.25p, 5.42std) 1.00x invariant, 0.04s (0.93d, 0.11p, 0.04std) 1.00x invariant, -0.03ms (-0.17d, 0.76p, 0.16std) 1.00x invariant, 0.07ms (0.01d, 0.98p, 6.29std)

@jkrumbiegel jkrumbiegel merged commit 64b382c into master Feb 1, 2024
17 checks passed
@jkrumbiegel jkrumbiegel deleted the jk/legend-scalar-colors branch February 1, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants