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

Improve error message for Plots.jl-like usage #3596

Merged
merged 2 commits into from Feb 4, 2024

Conversation

jkrumbiegel
Copy link
Collaborator

Fixes #3593

Example:

julia> p = lines(1:10)
       lines!(p, 1:20)
ERROR: ArgumentError: Tried plotting with `lines!` into a `FigureAxisPlot` object, this is not allowed.

The `FigureAxisPlot` object is returned by plotting functions not ending in `!` like `lines(...)` or `scatter(...)`.

It contains the new `Figure`, the new axis object, for example an `Axis`, `LScene` or `Axis3`, and the new plot object. It exists just as a convenience because returning it displays the contained figure. For all further operations, you should split it into its parts instead. This way, it is clear which of its components you are targeting.

You can do this with the destructuring syntax `fig, ax, plt = some_plot(...)` and then continue, for example with `lines!(ax, ...)`.

Stacktrace:
 [1] _create_plot!(::Function, ::Dict{Symbol, Any}, ::Makie.FigureAxisPlot, ::UnitRange{Int64})
   @ Makie ~/.julia/dev/Makie/src/figureplotting.jl:257
 [2] lines!(::Makie.FigureAxisPlot, ::Vararg{Any}; kw::@Kwargs{})
   @ MakieCore ~/.julia/dev/Makie/MakieCore/src/recipes.jl:176
 [3] top-level scope
   @ REPL[20]:2

@MakieBot
Copy link
Collaborator

MakieBot commented Feb 4, 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.44, 3.49) 0.02+- 367.08ms (308.66, 393.82) 38.88+- 469.91ms (467.23, 473.39) 2.27+- 7.19ms (7.11, 7.24) 0.05+- 25.46ms (25.36, 25.55) 0.06+-
master 3.47s (3.45, 3.48) 0.01+- 400.19ms (385.65, 408.63) 7.46+- 479.04ms (469.90, 522.08) 19.03+- 7.20ms (7.15, 7.27) 0.04+- 25.44ms (25.36, 25.49) 0.06+-
evaluation 1.00x invariant, 0.0s (0.06d, 0.92p, 0.01std) 1.09x noisy🤷‍♀️, -33.1ms (-1.18d, 0.07p, 23.17std) 1.02x invariant, -9.13ms (-0.67d, 0.25p, 10.65std) 1.00x invariant, -0.01ms (-0.19d, 0.72p, 0.04std) 1.00x invariant, 0.02ms (0.39d, 0.48p, 0.06std)
CairoMakie 3.08s (3.03, 3.10) 0.02+- 322.38ms (318.01, 328.57) 3.33+- 141.71ms (139.85, 143.29) 1.21+- 7.36ms (7.25, 7.43) 0.06+- 611.43μs (602.10, 622.95) 6.89+-
master 3.09s (3.06, 3.14) 0.03+- 319.54ms (317.35, 320.89) 1.31+- 140.14ms (139.19, 141.66) 0.80+- 7.33ms (7.27, 7.38) 0.04+- 604.28μs (596.08, 607.57) 3.88+-
evaluation 1.00x invariant, -0.0s (-0.10d, 0.85p, 0.03std) 0.99x invariant, 2.84ms (1.12d, 0.07p, 2.32std) 0.99x slower X, 1.57ms (1.53d, 0.02p, 1.01std) 1.00x invariant, 0.02ms (0.48d, 0.39p, 0.05std) 0.99x slower X, 7.15μs (1.28d, 0.04p, 5.39std)
WGLMakie 3.71s (3.69, 3.72) 0.01+- 323.37ms (320.27, 330.54) 3.66+- 8.88s (8.81, 8.94) 0.04+- 9.30ms (9.07, 10.08) 0.36+- 74.29ms (67.98, 78.64) 4.72+-
master 3.70s (3.67, 3.72) 0.02+- 321.14ms (317.89, 323.07) 1.80+- 9.05s (8.85, 9.35) 0.16+- 9.14ms (9.06, 9.20) 0.05+- 75.12ms (68.98, 82.13) 4.49+-
evaluation 1.00x invariant, 0.01s (0.82d, 0.16p, 0.01std) 0.99x invariant, 2.22ms (0.77d, 0.18p, 2.73std) 1.02x faster ✓, -0.17s (-1.45d, 0.03p, 0.10std) 0.98x invariant, 0.17ms (0.65d, 0.27p, 0.21std) 1.01x invariant, -0.83ms (-0.18d, 0.74p, 4.60std)

@jkrumbiegel jkrumbiegel merged commit 67e988b into master Feb 4, 2024
16 checks passed
@jkrumbiegel jkrumbiegel deleted the jk/improve-error-messages-figaxplot branch February 4, 2024 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add hint to f, ax, p=plot(x) to the FigureAxisPlot plot! error message
2 participants