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

[BUG] x and y seem to get switched around in recipe #4047

Closed
cjwyett opened this issue Jan 19, 2022 · 1 comment
Closed

[BUG] x and y seem to get switched around in recipe #4047

cjwyett opened this issue Jan 19, 2022 · 1 comment
Labels

Comments

@cjwyett
Copy link

cjwyett commented Jan 19, 2022

struct MyType
    x::Vector{Float64}
    y::Vector{Float64}
end

@recipe function mytypeplot(::Type{T}, mytype::T) where T <: MyType
    mytype.x, mytype.y
end

mytype = MyType([-2., -1., 0., 1., 2.], [1., 2., 3., 4., 5.])

plot(mytype, label="@recipe")
plot!(mytype.x, mytype.y, label="plot()")

I would expect the final 2 lines to plot the same thing. Only I get this:

plot

@BeastyBlacksmith
Copy link
Member

You should use a user recipe with the signature

@recipe function mytypeplot(mytype::T) where T <: MyType
    mytype.x, mytype.y
end

In the type recipe you have there the y-values are discarded, since it expects a single type whose recipe will be called and in your case, that is the standard recipe thats used for e.g. plot([-2, 1, 0, 1, 2])

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

No branches or pull requests

2 participants