jw3126 / UnitfulRecipes.jl

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

Tuple vs Vector behavior #71

Open DanDeepPhase opened 2 years ago

DanDeepPhase commented 2 years ago

When constructing lists from iterators, tuple and vectors yield different levels of wrapped data, which then gets differently ustripped when plotting. I personally find this tricky in Plots because I'm always putting tuples where vectors belong and vice versa.

using Plots
using Unitful, Unitful.DefaultSymbols, UnitfulRecipes
plot(cos,(0:180)°,label="Tuple")
plot!(cos,[0:180]°,label="Vector")

The vector comprehension ends up [(0:180)°] which then gets stripped to 0:180, whereas the Tuple version forms (0:180)° which uses degree math. So, the Tuple goes through half a rotation, and the Vector goes through 180 rotations.

gustaphe commented 2 years ago

That's not quite what's happening. Neither of them is a tuple.

julia> using Unitful
julia> x = (0:180)u"°";
julia> y = [0:180]u"°";

x is a StepRange, the same as 0u"°":1u"°":180u"°". That's why plotting it works. y is a Vector with a single element, which in turn is a StepRange.

But yes, it's strange that plot(cos, [x, 2x]) doesn't use the recipe, we'll have to look at that. In fact plot(cos, [x 2x]) also fails, strangely.