Using Unitful with Plots?

#1

Hi,

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")

gives

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?

0 Likes

#2

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

1 Like

#3

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.

3 Likes

#4

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

#5

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

0 Likes