jw3126 / UnitfulRecipes.jl

Plots.jl recipes for Unitful.jl arrays
MIT License
37 stars 10 forks source link

Error with `plot!(xticks)` #82

Closed JeffFessler closed 2 years ago

JeffFessler commented 2 years ago

This is kind of a continuation of #55. Currently xticks works fine as part of a plot call with other stuff (thanks to #56), but not in isolation with plot!. Here is a MWE:

using Unitful: mm
using UnitfulRecipes
using Plots: plot, plot!, gui
xticks = [0mm, 1mm]
plot([0mm, 2mm], [0mm, 3mm], xticks = xticks) # works
plot!(xticks = xticks) # fails

Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: DimensionError: -0.06 and 0.0 mm are not dimensionally compatible.
Stacktrace:
  [1] _lt
    @ ~/.julia/packages/Unitful/ApCuY/src/quantities.jl:272 [inlined]
  [2] <(x::Unitful.Quantity{Float64, NoDims, Unitful.FreeUnits{(), NoDims, nothing}}, y::Unitful.Quantity{Float64, 𝐋, Unitful.FreeUnits{(mm,), 𝐋, nothing}})
    @ Unitful ~/.julia/packages/Unitful/ApCuY/src/quantities.jl:262
  [3] <(x::Float64, y::Unitful.Quantity{Int64, 𝐋, Unitful.FreeUnits{(mm,), 𝐋, nothing}})
    @ Unitful ~/.julia/packages/Unitful/ApCuY/src/quantities.jl:264
  [4] <=(x::Float64, y::Unitful.Quantity{Int64, 𝐋, Unitful.FreeUnits{(mm,), 𝐋, nothing}})
    @ Base ./operators.jl:405
  [5] (::Plots.var"#93#95"{Float64, Float64})(t::Unitful.Quantity{Int64, 𝐋, Unitful.FreeUnits{(mm,), 𝐋, nothing}})
    @ Plots ~/.julia/packages/Plots/530RA/src/axes.jl:191

Perhaps the bug could be in Plots somewhere. But I am reporting it here initially because it works fine without units. Current workaround is to always specify xticks as part of plotting other stuff, instead of afterwards.

gustaphe commented 2 years ago

Good news and bad news:

This is not possible from a recipe, as no recipe processing happens for keyword arguments.

But as of recently this package is deprecated and the code lives in Plots, where there is actually a possibility to fix this (We just haven't merged the deprecation pr yet, hoping to have time later today).

JeffFessler commented 2 years ago

Hooray!