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

Categorical colormaps for meshes/poly or contour plots on meshes #3863

Closed
baxmittens opened this issue May 13, 2024 · 8 comments
Closed

Categorical colormaps for meshes/poly or contour plots on meshes #3863

baxmittens opened this issue May 13, 2024 · 8 comments
Labels
enhancement Feature requests and enhancements

Comments

@baxmittens
Copy link

Feature description

Hello,
first of all: Makie.jl is a great package. Thank you guys for your efforts.

What I would like to do is plot contours on a mesh or a poly.

using CairoMakie
f = Figure();
ax = Axis(f[1, 1]);
cmap = cgrad(:viridis, 2, categorical = true)
verts = Makie.GeometryBasics.Point2f[(0,0),(0,1),(1,0)]
colrs = [0,0,1]
poly!(ax, verts, color = colrs, colorrange=(0,1), colormap=cmap)
Colorbar(f[2, 1], limits = (0,1), colormap = cmap, vertical = false)
f

It seems like Makie is converting the color = colrs-values to colors first and then do an interpolation of the colors for each pixel in the triangle.

image

I would like to have it the other way around. First do an interpolation of the color = colrs-values and then transform it to a color according to the colormap.

image

Is there a way to do this in Makie right now?

Thx in advance.

Graetz max

@baxmittens baxmittens added the enhancement Feature requests and enhancements label May 13, 2024
@asinghvi17
Copy link
Member

What you ask for will work in GLMakie but not in CairoMakie, since vector graphics standards only support interpolation over colours in meshes and not values.

@baxmittens
Copy link
Author

baxmittens commented May 15, 2024

Thank you for your answer @asinghvi17 .

Can you tell me how this would work or guide me to an example somewhere?

I want to achieve something like that (which is, I think, a standard way to do color plots for field results)

image

For the latter, I refined the mesh to 3_066_880 elements and provided a constant color for each element, which looks okay but is not perfect.

@asinghvi17
Copy link
Member

Hmm, in this case I would use tricontourf instead, if you have a known mesh. You can create a DelaunayTriangulation.Triangulation from that mesh, and pass it to tricontourf.

As you saw, GLMakie will do the interpolation correctly, but if you need a vector renderer then tricontourf should do the job!

@baxmittens
Copy link
Author

baxmittens commented May 17, 2024

Hey @asinghvi17

thanks again for your answer.
tricontourf is exactly what I was looking for.
But as the name is tricontourf, I am a bit irritated that I cannot provide a vector with vertices and a vector with indices to that method like

vertices = Point2f[ ... ]
indices = Tuple{Int,Int,Int}[(1,2,3),(2,3,4),...]
vertexcolors = rand(Float64, length(vertices))
tricontourf(vertices, indices, color=vertexcolors)

That would be so easy and convenient. I looked in the recipe, but it would be hard for me to alter.
DelaunayTriangulation.Triangulation is such a high-level construct. Since my domain is non-convex, I would have to compute the boundary of the domain first and provide it as a closed loop (or am I wrong here?). But I know the triangulation so I would rather want to avoid that.

Maybe there is a different solution?
But if not, I think it would maybe be a useful addition to that method to support a triangulation in the notation described above (or some triangle mesh from Meshes.jl).

@jkrumbiegel
Copy link
Member

Maybe @DanielVandH could clarify

@DanielVandH
Copy link
Contributor

DanielVandH commented May 17, 2024

The tricontourf docstring mentions this case:

  triangulation = DelaunayTriangulation() — The mode with which the points in xs and ys are triangulated. Passing DelaunayTriangulation() performs a Delaunay triangulation. You can also pass a preexisting triangulation as an AbstractMatrix{<:Int} with size (3, n), where each column specifies the vertex    
  indices of one triangle, or as a Triangulation from DelaunayTriangulation.jl.

Just make your indices a matrix and use triangulation = indices.

@baxmittens
Copy link
Author

Thank you very much. This is what I was looking for. Closing this for now...

@baxmittens
Copy link
Author

@asinghvi17 @jkrumbiegel @DanielVandH

Got figured it out.
The result is an 80KB PDF graphic that looks ridiculously beautiful.
This is plain nuts. Thank you for being so supportive.

temp.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests and enhancements
Projects
None yet
Development

No branches or pull requests

4 participants