Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuple vs Vector behavior #71

Open
DanDeepPhase opened this issue Apr 2, 2022 · 1 comment
Open

Tuple vs Vector behavior #71

DanDeepPhase opened this issue Apr 2, 2022 · 1 comment

Comments

@DanDeepPhase
Copy link
Contributor

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
Copy link
Collaborator

gustaphe commented Apr 2, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants