JuliaGraphics / Winston.jl

2D plotting for Julia
MIT License
171 stars 55 forks source link

broken savefig for .eps/.pdf #228

Closed acroy closed 9 years ago

acroy commented 9 years ago

Trying to save a figure to a PDF or EPS file using savefig gives the following error for me on 0.3.11-pre (OSX+Linux):

julia> savefig("test.pdf")
ERROR: `convert` has no method matching convert(::Type{Float64}, ::SubString{UTF8String})
 in convert at base.jl:13
 in _str_size_to_pts at /Users/ac/.julia/v0.3/Winston/src/renderer.jl:54
 in savepdf at /Users/ac/.julia/v0.3/Winston/src/Winston.jl:1868
 in savefig at /Users/ac/.julia/v0.3/Winston/src/Winston.jl:1903
 in savefig at /Users/ac/.julia/v0.3/Winston/src/plot.jl:14

The problem seems to be that @compat Float64(m.captures[1]) in renderer.jl actually translates into convert(Float64, m.captures[1]) which doesn't work for 0.3. Providing a custom convert, e.g.

Base.convert(::Type{Float64}, s::SubString{UTF8String}) = float64(s)

leads to a new error though:

ERROR: `*` has no method matching *(::Nothing, ::Float64)
 in _str_size_to_pts at /Users/ac/.julia/v0.3/Winston/src/renderer.jl:56
 in saveeps at /Users/ac/.julia/v0.3/Winston/src/Winston.jl:1859
 in savefig at /Users/ac/.julia/v0.3/Winston/src/Winston.jl:1903
 in savefig at /Users/ac/.julia/v0.3/Winston/src/plot.jl:14
mvkma commented 9 years ago

Maybe it could be fixed like this: 4e3c005a69a4eccdea52e3c777a3e539ebdc2793? It works for me on 0.3.10 and 0.4.0-dev+5769. I'm not sure though, if there is a preferred way for these sort of conversions (maybe float or something).

acroy commented 9 years ago

@slangangular : It seems my hack actually works if I provide the additional convert function before doing anything with Winston.

But your solutions is more elegant IMO. Apparently parse(type, str) isn't documented under 0.3, but it seems to work well (and the 0.4-docs suggest that it is the function we want).

mvkma commented 9 years ago

Under 0.3 parse(type, str) only works because of Compat. I think that's okay though, because Winston relies on Compat anyways and parsefloat is deprecated in 0.4.

acroy commented 9 years ago

Thanks!