Using Unitful with Plots?



Can I plot Unitful numbers with Plots?

using Plots
using Unitful
plot([0.0, 1.0, 2.0]u"s", [3.5, 2.5, 1.5]u"V")


DimensionError: Inf and 0.0 s are not dimensionally compatible.

Is there a way to make it work without stripping out the units before passing it to Plots?



there is a package, UnitfulPlots.jl, that maybe is a solution, but i can’t make it work.

1 Like


In the end, somewhere, you have to strip the units because the backends want floating point numbers. What UnitfulPlots.jl does is supply recipes that check unit compatibility, add labels, and then strip and pass to the next stage of the plotting pipeline.



If you just want a solution to plotting things with Unitful values and don’t care about what package you use to do things, current master of Gadfly should “just work” as is. Unfortunately there hasn’t been a release since the PR adding Unitful support was merged, so you will have to checkout the master branch. Depending on the state of things, you may also have to checkout the master branch of Compose to get Gadfly working properly.

1 Like


Thanks for the replies - will be back to those in the coming days.