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

Can I use fig.show()? #1

Open
pfebrer opened this issue Sep 7, 2020 · 2 comments
Open

Can I use fig.show()? #1

pfebrer opened this issue Sep 7, 2020 · 2 comments

Comments

@pfebrer
Copy link

pfebrer commented Sep 7, 2020

Hi!

I want to use sphinx-gallery to document a package that uses plotly as the visualization tool. As in this repo, I used the custom image scrapper, but I wonder why it does not capture the output of

fig.show()

and you have to do

plotly.io.show(fig)

Or is it just me that I have the problem?

The reason I'd like the first one to work is because it feels weird to write an example with plotly.io.show(fig), since nobody is going to actually use this in "real life".

Thank you!

@pfebrer
Copy link
Author

pfebrer commented Sep 8, 2020

Since I have plotly's Figure wrapped in my own class and sphinx-gallery looks for the _repr_html_ method of the returned object I just added the following method to my class:

class MyClass:
    ...

    def _repr_html_(self):
        return plotly.io.to_html(self.figure, full_html=False) # (self.figure is a plotly Figure)

and then

plot = MyClass()

plot

works well as a workaround without needing the plotly custom scraper, for anyone who might read this.

However, I still would prefer that plot.show (which calls plot.figure.show()) would work so that I could display more than one plot in a code block. Any chance this can work? :)

@pfebrer
Copy link
Author

pfebrer commented Sep 8, 2020

I just realised that _repr_html_ is already implemented for plotly >= 4.8.0 and I was using 4.7.1, sorry for all the comments :)

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

1 participant