Closed agerlach closed 3 years ago
Yep I'm not sure how we could handle that. AFAIU, this is actually not going through the recipe. E.g., without UnitfulRecipes, if you try
using Plots, Unitful
plot(rand(3), xunit=u"m")
you'll get the same error I think.
A workaround would be to first make an empty cool plot in ft and then add the data in m:
julia> mycoolplot(Float64[]*u"ft", Float64[]*u"ft") # works and sets the frame in ft
julia> mycoolplot!(20*rand(3)*u"m", 20*rand(3)*u"m") # now works and is converted to ft
🤷
Thanks for the quick reply. Yeah, that produces the same error. Based on your suggestion, I think I'll use this as a convenient hack
@userplot UnitsPlot
@recipe function f(mcp::UnitsPlot)
ux = mcp.args[1]
uy = length(mcp.args) > 1 ? mcp.args[2] : ux
if length(mcp.args) > 2
return Float64[]*ux, Float64[]*uy, Float64[]*mcp.args[3]
else
return Float64[]*ux, Float64[]*uy
end
end
unitsplot(u"ft")
mycoolplot!(20*rand(3)*u"m", 20*rand(3)*u"ft")
unitsplot(u"ft", u"m")
mycoolplot!(20*rand(3)*u"m", 20*rand(3)*u"ft")
Actually, this is probably cleaner
@recipe function f(ux::Unitful.FreeUnits, uy::Unitful.FreeUnits = ux)
label := nothing
Float64[]*ux, Float64[]*uy
end
@recipe function f(ux::Unitful.FreeUnits, uy::Unitful.FreeUnits, uz::Unitful.FreeUnits)
label := nothing
Float64[]*ux, Float64[]*uy, Float64[]*uz
end
plot(u"ft", u"m")
mycoolplot!(20*rand(3)*u"m", 20*rand(3)*u"ft")
The calls where
vline
has ayunit
andhline
has axunit
producesI realize that it doesn't really make sense to spec
yunit
forvline
andxunit
forhline
, but this issue creeps up usingvline
andhline
series types in a user recipe, e.g.