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

Tricontourf plot #2226

Merged
merged 24 commits into from
Sep 23, 2022
Merged

Tricontourf plot #2226

merged 24 commits into from
Sep 23, 2022

Conversation

jkrumbiegel
Copy link
Member

@jkrumbiegel jkrumbiegel commented Aug 17, 2022

Description

Adds a tricontourf plot type.

using CairoMakie
using Random

Random.seed!(1234)

x = randn(100)
y = randn(100)
z = x .* y

Makie.tricontourf(x, y, z, colormap = :heat)
scatter!(x, y, color = z, colormap = :heat, strokewidth = 1, strokecolor = :black)
current_figure()

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 or changed relevant sections in the documentation
  • Added unit tests for new algorithms, conversion methods, etc.
  • Added reference image tests for new plotting functions, recipes, visual options, etc.

@MakieBot
Copy link
Collaborator

MakieBot commented Aug 17, 2022

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(display(fig))
using create display create display
GLMakie 22.24s (21.27, 23.34) 0.73+- 24.21s (23.15, 25.60) 0.97+- 22.24s (21.29, 23.25) 0.77+- 26.16ms (25.29, 26.88) 0.55+- 137.92ms (135.15, 141.10) 1.96+-
master 22.11s (21.20, 22.89) 0.66+- 24.11s (23.27, 24.76) 0.51+- 22.40s (21.68, 23.01) 0.51+- 26.20ms (25.65, 26.76) 0.39+- 137.53ms (133.14, 140.01) 2.68+-
evaluation +0.61%, 0.14s invariant (0.20d, 0.72p, 0.69std) +0.41%, 0.1s invariant (0.13d, 0.82p, 0.74std) -0.75%, -0.17s invariant (-0.25d, 0.64p, 0.64std) -0.18%, -0.05ms invariant (-0.10d, 0.86p, 0.47std) +0.29%, 0.4ms invariant (0.17d, 0.76p, 2.32std)
CairoMakie 16.32s (16.00, 16.67) 0.23+- 22.23s (21.19, 24.48) 1.13+- 3.80s (3.38, 4.17) 0.30+- 21.45ms (20.89, 22.56) 0.55+- 29.85ms (27.45, 31.64) 1.36+-
master 15.99s (15.21, 16.53) 0.47+- 22.32s (20.79, 23.56) 0.90+- 3.64s (3.36, 3.78) 0.16+- 21.90ms (20.97, 22.83) 0.63+- 30.15ms (28.80, 31.84) 1.07+-
evaluation +2.03%, 0.33s invariant (0.90d, 0.13p, 0.35std) -0.43%, -0.1s invariant (-0.09d, 0.86p, 1.01std) +4.17%, 0.16s invariant (0.66d, 0.25p, 0.23std) -2.10%, -0.45ms invariant (-0.76d, 0.18p, 0.59std) -1.01%, -0.3ms invariant (-0.25d, 0.65p, 1.21std)
WGLMakie 20.25s (19.66, 20.95) 0.39+- 27.23s (26.84, 28.06) 0.52+- 44.14s (43.65, 45.37) 0.58+- 22.94ms (22.27, 23.95) 0.56+- 1.74s (1.70, 1.78) 0.03+-
master 20.00s (19.81, 20.46) 0.23+- 27.09s (26.78, 27.66) 0.30+- 44.26s (43.60, 45.12) 0.59+- 22.99ms (22.50, 23.65) 0.40+- 1.75s (1.70, 1.80) 0.04+-
evaluation +1.21%, 0.24s invariant (0.76d, 0.19p, 0.31std) +0.53%, 0.14s invariant (0.34d, 0.54p, 0.41std) -0.27%, -0.12s invariant (-0.20d, 0.72p, 0.59std) -0.23%, -0.05ms invariant (-0.11d, 0.84p, 0.48std) -0.62%, -0.01s invariant (-0.33d, 0.55p, 0.03std)

@github-actions
Copy link
Contributor

Missing reference images

Found 3 new images without existing references.
Upload new reference images before merging this PR.

@jkrumbiegel jkrumbiegel marked this pull request as ready for review August 21, 2022 11:14
@kimauth
Copy link

kimauth commented Aug 21, 2022

This looks super cool! 💜

It seems like it always computes the connectivity pattern between the points (trianglelist) by a Delaunay triangulation right now. Coming from finite elements, it is common in my field to have that pattern available. Are there any plans to allow handing it over to tricontourf? And would knowing the triangulation actually be enough to do contour plots on non-convex domains, too?

@jkrumbiegel
Copy link
Member Author

jkrumbiegel commented Aug 21, 2022

Oh sure that could definitely be an option. I don't really know much about tricontourf plots and just implemented what I thought was the most common usage pattern. You could look in the source where I pass the list of triangles to the contour generating function and just pass your triangles in there and see if it works? We could just make the triangulation mode an attribute and maybe the default would be :delaunay but one could pass a list of triangles instead.

@jkrumbiegel
Copy link
Member Author

I have no idea if the contour generation function needs a specific form of triangulation though.

@jkrumbiegel
Copy link
Member Author

I just added the option to pass a matrix as triangles (probably should add a vector of triangle faces from GeometryBasics as well, and it seems fine:

using CairoMakie
x = [0.0, 0.5, 1.0, 0.25, 0.75, 0.5]
y = sqrt(3)/2*[0.0, 0.0, 0.0, 0.5, 0.5, 1.0]
z = [0.0, 0.5, 0.0, 1.0, 1.0, 0.0]
f, ax, _ = tricontourf(x, y, z, triangles = [
    1 2 4
    2 3 5
    4 5 6
]')
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
tricontourf(f[1, 2], x, y, z, triangles = Makie.DelaunayTriangulation())
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
f

image

@github-actions
Copy link
Contributor

Missing reference images

Found 3 new images without existing references.
Upload new reference images before merging this PR.

@kimauth
Copy link

kimauth commented Aug 22, 2022

That's exactly what I needed, thanks for putting it in so quickly!

I gave it a trial run with some of my real data, it worked great:
test_tricontourf
(In the past I used to put a fine regular grid over my data to obtain this type of plot, now it is only a few lines from the Ferrite.jl data structures to the plot.)

@jkrumbiegel
Copy link
Member Author

Cool, that's good to know! I'll continue with that path then. Maybe I'll call the parameter triangulation instead of triangles

@github-actions
Copy link
Contributor

Missing reference images

Found 4 new images without existing references.
Upload new reference images before merging this PR.

@github-actions
Copy link
Contributor

Missing reference images

Found 4 new images without existing references.
Upload new reference images before merging this PR.

@github-actions
Copy link
Contributor

Missing reference images

Found 4 new images without existing references.
Upload new reference images before merging this PR.

@github-actions
Copy link
Contributor

Missing reference images

Found 4 new images without existing references.
Upload new reference images before merging this PR.

@github-actions
Copy link
Contributor

Missing reference images

Found 4 new images without existing references.
Upload new reference images before merging this PR.

@github-actions
Copy link
Contributor

Missing reference images

Found 4 new images without existing references.
Upload new reference images before merging this PR.

@jkrumbiegel
Copy link
Member Author

jkrumbiegel commented Sep 17, 2022

This needs some refactoring so that code duplication with contourf is reduced. Also, currently each triangle generates its own polygon for each band, so we get edge artifacts in CairoMakie, but not GLMakie:

image

Even though the bands run continuously across several triangles, the triangle borders are always visible with white artifacts.

Edit: We might work-around this issue by just dispatching on tricontourf in CairoMakie and drawing all paths of one color together before calling fill. This will effectively treat the patches as one big surface.

@github-actions
Copy link
Contributor

Missing reference images

Found 4 new images without existing references.
Upload new reference images before merging this PR.

@jkrumbiegel
Copy link
Member Author

Should be ok now

@github-actions
Copy link
Contributor

Missing reference images

Found 4 new images without existing references.
Upload new reference images before merging this PR.

@github-actions
Copy link
Contributor

Missing reference images

Found 4 new images without existing references.
Upload new reference images before merging this PR.

@jkrumbiegel jkrumbiegel reopened this Sep 23, 2022
@jkrumbiegel jkrumbiegel merged commit e2e5010 into master Sep 23, 2022
@jkrumbiegel jkrumbiegel deleted the jk/tricontourf branch September 23, 2022 08:34
@jkrumbiegel jkrumbiegel mentioned this pull request Oct 8, 2022
5 tasks
@thomvet
Copy link

thomvet commented Oct 13, 2022

Just wanted to say thank you for creating this! Have a year ago I posted a hacky and ugly coded version of it on discourse (and got some help making it work!).

And now it's a full blown recipe inside Makie! Greatly appreciated!

t-bltg pushed a commit to t-bltg/Makie.jl that referenced this pull request Dec 31, 2022
* initial attempt of tricontourf

* use miniqhull instead

* use modified implementation of getting contours

* add docs page

* colormap example

* add colorbar to docs

* add visual tests

* add compat bounds

* use static rng

* add option to pass matrix of triangles instead

* shift to separate file

* add triangulation example

* add same example to tests

* add news

* fix missing contours

* type plot function correctly for method errors

* add CairoMakie tricontourf override

* map(Point2f

* factor out shared code between contourf and tricontourf

Co-authored-by: Simon <sdanisch@protonmail.com>
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.

None yet

5 participants