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

Plot to screen after writemime() deprecation #494

Closed
mbaz opened this issue Jan 2, 2017 · 4 comments
Closed

Plot to screen after writemime() deprecation #494

mbaz opened this issue Jan 2, 2017 · 4 comments

Comments

@mbaz
Copy link

mbaz commented Jan 2, 2017

I'm trying to update Gaston for use in IJulia after the writemime() deprecation in Julia 0.5

In Julia 0.4, I had this function to generate a plot for use in an IJulia notebook:

function writemime(io::IO, ::MIME"image/png", x::Figure)
    # The plot is written to /tmp/gaston-ijula.png. Read the file and
    # write it to io.
    data = open(readbytes, "$(gnuplot_state.tmpdir)gaston-ijulia.png","r")
    write(io,data)
end

Following the discussion in JuliaLang/julia#14052, I changed the function definition to

function show(::MIME"image/png", io::IO, x::Figure)

I also import Base.show instead of Base.writemime; I also tried reversing the order of MIME and io. However, when I try plotting in a notebook, I get the textual description of the plot, not the plot itself. How should I update my code to make it work again?

(I'm not sure if this is the right forum for this question, but nothing seems to be an obvious fit. Please let me know if I should post this somewhere else.)

@stevengj
Copy link
Member

stevengj commented Jan 2, 2017

Your arguments are in the wrong order. Define @compat function Base.show(io::IO, ::MIME"image/png", x::Figure) (with @compat there if you want to support 0.4 too).

@stevengj
Copy link
Member

stevengj commented Jan 2, 2017

@stevengj
Copy link
Member

stevengj commented Jan 2, 2017

i.e. basically you just need to do a search-and-replace of writemime with show; the arguments are the same.

@mbaz
Copy link
Author

mbaz commented Jan 2, 2017

Thanks for your help. Defining Base.show() instead of show() did the trick.

@mbaz mbaz closed this as completed Jan 2, 2017
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