I am trying to plot a vector with Quanities with Makie. I tried defining the following, where getval is a custum function that returns the val field of its input:
scatter(xs::Vector{Quantity}, ys::Vector{Quantity}; kwargs...) = scatter(xs|>getval, ys|>getval; kwargs...)
scatter(xs::Vector, ys::Vector{Quantity}; kwargs...) = scatter(xs, ys|>getval; kwargs...)
scatter(xs::Vector{Quantity}, ys::Vector; kwargs...) = scatter(xs|>getval, ys; kwargs...)
However, based on the line that errored in the stacktrace, I am able to deduct that I should look into
https://github.com/JuliaPlots/AbstractPlotting.jl/blob/master/src/recipes.jl
, where I find:
# All plot types
convert_arguments(P::Type{<:AbstractPlot}, x::MyType) = convert_arguments(P, rand(10, 10))
# Only for scatter plots
convert_arguments(P::Type{<:Scatter}, x::MyType) = convert_arguments(P, rand(10, 10))
I do not really understand what to make of the examples. I have tried defining
convert_arguments(P::Type{<:Scatter}, x::Quantity, y::Quantity) = convert_arguments(P, getval(x), getval(y))
and
convert_arguments(P::Type{<:Scatter}, x::Quantity) = convert_arguments(P, getval(x))
, but without luck.
Any good ideas on how to plot values of type Quantity with Makie?
The recipe system is not working basically. I have some open issues there where you can learn more.
I reckon at this stage your best option is to always explicitly strip the unit and add it to the labels... If you want to go the recipe way, maybe UnitfulRecipes.jl can serve as a guide, although the internals of Plots.jl are quite different so I'm pretty sure you can't translate everything to Makie...
Last updated: Nov 06 2024 at 04:40 UTC