# Makie: How to convert keyword arguments in addition to positional arguments?

**URL:** <https://discourse.julialang.org/t/makie-how-to-convert-keyword-arguments-in-addition-to-positional-arguments/130405>\
**Category:** General Usage\
**Tags:** question, plotting, makie\
**Created:** [July 2, 2025, 8:24am UTC](https://discourse.julialang.org/t/makie-how-to-convert-keyword-arguments-in-addition-to-positional-arguments/130405 "2025-07-02T08:24:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fverdugo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fverdugo/32/9446_2.png) [@fverdugo](https://discourse.julialang.org/u/fverdugo)\
**Post date:** [July 2, 2025, 8:24am UTC](https://discourse.julialang.org/t/makie-how-to-convert-keyword-arguments-in-addition-to-positional-arguments/130405/1 "2025-07-02T08:24:28Z")

</div>

Hi,

When calling say `Makie.mesh(args...;kwargs...)` for some arguments with user defined-type, one can define an argument conversion for the positional arguments `args` using function `Makie.convert_arguments`.

**But how to convert the keyword arguments `kwargs` ?** I also have some user-defined types in the keyword arguments that can be mapped to the usual keyword arguments.

As a fallback, I am trying to define method

```julia
funciton Makie.plot!(p::Makie.Mesh{<:Tuple{<:MyType}})
   ## ... Some conversions ...
   Makie.mesh!(p,converted_args...;converted_kwargs...)
end

```

which gives access to the keyword arguments as well, But it does not work for `Makie.Mesh`.

Any clue on how to convert keyword arguments?

Thanks!

cc @sdanisch @jules

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [July 2, 2025, 10:05am UTC](https://discourse.julialang.org/t/makie-how-to-convert-keyword-arguments-in-addition-to-positional-arguments/130405/2 "2025-07-02T10:05:47Z")

</div>

You can overload `convert_attribute(value::YourType, ::Makie.key"attribute", ::Makie.key"mesh")` .  
See: [Makie.jl/Makie/src/conversions.jl at master · MakieOrg/Makie.jl · GitHub](https://github.com/MakieOrg/Makie.jl/blob/master/Makie/src/conversions.jl#L910-L937) for some examples.  
Note, these will only get applied automatically for core Makie plots, not for user recipes, since it’s a bit hard to foresee what people want to do with e.g. a `color` attribute.

---

<div class="post-metadata">

**Author:** ![fverdugo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fverdugo/32/9446_2.png) [@fverdugo](https://discourse.julialang.org/u/fverdugo)\
**Post date:** [July 2, 2025, 10:26am UTC](https://discourse.julialang.org/t/makie-how-to-convert-keyword-arguments-in-addition-to-positional-arguments/130405/3 "2025-07-02T10:26:12Z")

</div>

Hi @sdanisch

thanks for the quick reply.

To convert the attribute, I need both the attribute and the passed argument. I guess you only have the attribute in `convert_attribute`.

This is my actual setting (after simplifying a bit): I have a custom type that contains a mesh plus a dict with arrays of data associated with the nodes of the mesh:

```julia
struct MeshWithData
    mesh::SomeMeshType
    node_data::Dict{String,Vector{Float64}}
end
struct NodeColor
    name::String
end

```

I want this API:

```julia
foo = MeshWithData(...)
Makie.mesh(foo;color=NodeColor("dataname"))

```

Which should colorate foo according to the data in key “dataname”.

**Any ideas how to achieve this?** I was hopping to dispatch on `NodeColor` somewhere.

BTW, I cannot pass directly the array of data like this

```julia
Makie.mesh(foo;color=foo.node_data["dataname"])

```

since the conversion of `foo.mesh` will possibly create and destroy nodes and `foo.node_data["dataname"]` will become out of sync.

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [July 2, 2025, 1:52pm UTC](https://discourse.julialang.org/t/makie-how-to-convert-keyword-arguments-in-addition-to-positional-arguments/130405/4 "2025-07-02T13:52:02Z")

</div>

You can add whatever vertex data you want to a mesh and it’ll expand like positions, normals, etc:

```julia
using GeometryBasics

m = normal_mesh(Rect3f(0,0,0,1,1,1), facetype = QuadFace{Int})
# Mesh{3, Float32, QuadFace{Int64}}
# faces: 6
# vertex position: 8
# vertex normal: 6

m2 = GeometryBasics.mesh(
    m, 
    color = [RGBf(x, y, z) for x in 0:1 for y in 0:1 for z in 0:1],
    vertex_name = string.(1:8),
    face_name = per_face(string.(1:6), m)
)
# Mesh{3, Float32, NgonFace{3, OffsetInteger{-1, UInt32}}}
# faces: 12
# vertex position: 8
# vertex normal: 6
# vertex color: 8
# vertex vertex_name: 8
# vertex face_name: 6

expand_faceviews(m2)
# Mesh{3, Float32, NgonFace{3, OffsetInteger{-1, UInt32}}}
# faces: 12
# vertex position: 24
# vertex normal: 24
# vertex color: 24
# vertex vertex_name: 24
# vertex face_name: 24

```

If you need to do further processing with the data before plotting you can run `expand_faceviews()` like this and pass the result to `Makie.mesh` with the processed data as attributes.

---

<div class="post-metadata">

**Author:** ![fverdugo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fverdugo/32/9446_2.png) [@fverdugo](https://discourse.julialang.org/u/fverdugo)\
**Post date:** [July 2, 2025, 2:09pm UTC](https://discourse.julialang.org/t/makie-how-to-convert-keyword-arguments-in-addition-to-positional-arguments/130405/5 "2025-07-02T14:09:28Z")

</div>

Hi @ffreyer,

Thanks for the hint. In a more complex example, I would like pass a function-like object in the color attribute and interpolate it on the mesh nodes, and use the resulting vector as color. So, I need a way of converting an attribute while having access to the positional arguments.

I provably will define a new recipe (which gives grater control) instead of trying to extend `Makie.mesh`.

But it would be cool to use a function that already exists (Makie.mesh) instead of creating a new one, if the difference is mainly conversions of arguments/attributes.

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [July 2, 2025, 2:31pm UTC](https://discourse.julialang.org/t/makie-how-to-convert-keyword-arguments-in-addition-to-positional-arguments/130405/6 "2025-07-02T14:31:06Z")

</div>

Yea `convert_attribute()` only considers the attribute itself, so you’d need something else. Maybe it’s useful to note that `Makie.mesh` can extract colors from a mesh and that the positions don’t change in `convert_arguments`/`expand_faceviews`. They just get duplicated. So you can figure out your vertex colors without worrying about what the plot function does to the mesh.

```julia
function build_mesh(N)
    ps = [Point2f(x, y) for x in 1:N for y in 1:2]
    fs = [QuadFace(2x-1, 2x, 2x+2, 2x+1) for x in 1:N-1]
    cs = per_face([x % 2 for x in 1:N-1], fs)
    return GeometryBasics.mesh(ps, fs, color = cs)
end
fig = Figure()
sl = Slider(fig[1,1], range = 2:20, startvalue = 20)
Makie.mesh(fig[2,1], map(build_mesh, sl.value))
fig

```
