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

y Scale options do not work for a list of functions properly #1330

Closed
CNOT opened this issue Oct 19, 2019 · 2 comments · Fixed by #1331
Closed

y Scale options do not work for a list of functions properly #1330

CNOT opened this issue Oct 19, 2019 · 2 comments · Fixed by #1331

Comments

@CNOT
Copy link

CNOT commented Oct 19, 2019

I've got a function that as an input takes a list of values and returns an array of functions that I'd like to plot with Gadfly. Everything works fine until I try to plot it in any of the y-scales, then suddenly no plots are produced.
Here's a MWE:

using Gadfly
function test_f(a)
    return [x -> a[i]*x for i in 1:length(a)]
end
plot(test_f(1:10),1,2π) |> SVG("test.svg")

produces:

test.pdf

However,

plot(test_f(1:10),1,2π,Scale.y_log10()) |> SVG("test.svg")

fails to produce any plots and gives the following error:

MethodError: no method matching log10(::getfield(Main, Symbol("##10#12")){Int64,UnitRange{Int64}})
Closest candidates are:
log10(!Matched::BigFloat) at mpfr.jl:671
log10(!Matched::Missing) at math.jl:1072
log10(!Matched::Complex{Float16}) at math.jl:1020
...

@CNOT
Copy link
Author

CNOT commented Oct 19, 2019

So I did some more digging, and I could be wrong but I believe the issue is that Gadfly doesn't use the operator for applying the composite functions that come up in Gadfly.Scale.

For example:

f = log10(x->x^2)

would produce a similar error to the one I posted earlier. However:

f = log10 ∘ (x->x^2)

seems to work properly.

@CNOT
Copy link
Author

CNOT commented Oct 19, 2019

A workaround was suggested in Slack by Gerhard Aigner. I'll just write it down, in case anyone else ends up here facing the same issue.

Use Function in the function's definition:

function test_f(a)
    return Function[x -> a[i]*x for i in 1:length(a)]
end

bjarthur added a commit that referenced this issue Oct 20, 2019
Fix #1330 handle closures with special scaling
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

Successfully merging a pull request may close this issue.

1 participant