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

In a Jupyter notebook, no display when poof is in a separate cell #380

Closed
fdion opened this issue Apr 3, 2018 · 9 comments
Closed

In a Jupyter notebook, no display when poof is in a separate cell #380

fdion opened this issue Apr 3, 2018 · 9 comments
Labels
level: intermediate python coding expertise required priority: high should be done before next release type: bug something isn't working

Comments

@fdion
Copy link
Contributor

fdion commented Apr 3, 2018

if visualizer.poof() is called in a separate cell, no visualization appears, as the empty plot has already been rendered in the call for fit(). Workaround is to access visualizer.ax.get_figure().

Issue

For extra detail, see demo notebook linked in Background section

Code Snippet

Tested using the bike share data set from the YB intro

In one cell:

visualizer = Rank1D()
visualizer.fit(X,y)
visualizer.transform(X)

In a separate cell:
visualizer.poof()

Background

Demo notebook
https://gist.github.com/fdion/d645e164f6969d269aff681efa31ef96

@ndanielsen
Copy link
Contributor

@fdion thanks exploring this package and then creating this issue when you found the bug. We'll take a look at the api and resolve this bug around the use case.

@ndanielsen ndanielsen added type: bug something isn't working level: intermediate python coding expertise required priority: high should be done before next release labels Apr 3, 2018
@ndanielsen
Copy link
Contributor

ndanielsen commented Apr 3, 2018

potentially related issue with the viz.poof() method #375

@fdion
Copy link
Contributor Author

fdion commented Apr 3, 2018

#375 would fix the display when poof is called (I tested it by adding return ax to poof), but it wont prevent the display of the empty figure when fit is called.

@bbengfort
Copy link
Member

bbengfort commented Apr 3, 2018

This is a tough one; poof is a wrapper for visualizer.finalize() + visualizer.show() or visualizer.savefig(). Perhaps one work around is to use visualizer.finalize() instead of visualizer.poof() so the call to show doesn't execute?

The notebook should get the ax returned from finalize and display the result.

Not sure how to handle the empty figure though, fit() should return self not self.ax so it could be a bug with Rank1D.

@dnabanita7
Copy link
Contributor

dnabanita7 commented Feb 13, 2019

As in https://github.com/DistrictDataLabs/yellowbrick/blob/develop/yellowbrick/base.py
the fit method returns self,the draw method returns nothing and checks a Not Implemented Error,the finalize method returns self.ax.While poof method wraps up finalize method at first which returns self.ax and a follow up if-else statement wraps either plt.show method or plt.savefig method.

    def poof(self, outpath=None, clear_figure=False, **kwargs):
        """
        Poof makes the magic happen and a visualizer appear! You can pass in
        a path to save the figure to disk with various backends, or you can
        call it with no arguments to show the figure either in a notebook or
        in a GUI window that pops up on screen.
        Parameters
        ----------
        outpath: string, default: None
            path or None. Save figure to disk or if None show in window
        clear_figure: boolean, default: False
            When True, this flag clears the figure after saving to file or
            showing on screen. This is useful when making consecutive plots.
        kwargs: dict
            generic keyword arguments.
        Notes
        -----
        Developers of visualizers don't usually override poof, as it is
        primarily called by the user to render the visualization.
        """
        # Ensure that draw has been called
        if self._ax is None:
            warn_message = (
                "{} does not have a reference to a matplotlib.Axes "
                "the figure may not render as expected!"
            )
            warnings.warn(
                warn_message.format(self.__class__.__name__), YellowbrickWarning
            )

        # Finalize the figure
        self.finalize()

        if outpath is not None:
            plt.savefig(outpath, **kwargs)
        else:
            plt.show()

        if clear_figure:
            plt.gcf().clear()

Hence poof in documentation wraps up visualizer.finalize() and plt.show() or plt.savefig().

So,shall I change the Rank1D code,please guide what to do?

@bbengfort
Copy link
Member

Hi @naba7 thank you for your note - I did check Rank1D and it looks like it does indeed return self so no change needs to be made to that. If you're interested in taking a look at this, perhaps you can see if you can reproduce the bug using the notebook that @fdion provided on YB v0.9.1? It is possible that this bug has been repaired through a different change.

@dnabanita7
Copy link
Contributor

dnabanita7 commented Feb 13, 2019 via email

@naresh-bachwani
Copy link
Contributor

I went through this issue and after exploring it a bit I found a few fixes. This is still an issue and needs to be rectified.
1. poof returns self.ax
This certainly produces an output but not an image. The outputs are axes. However, @fdion said that he was getting a display, there can be a different setting to get one. A notebook showing my outputs.
https://gist.github.com/naresh-bachwani/80f90fd4c315cda0e12088625634f20d

2, poof returns self.ax.get_figure()(Requires research, experiments and suggestions )
This produces an output when poof() is called from a different cell but also produce two images when used in the same cell. The notebook showing outputs when poof returns self.ax.get_figure()
https://gist.github.com/naresh-bachwani/567e3b03fff7e400c7fad90c407a0841

@bbengfort
Copy link
Member

I believe this has been fixed by #953

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level: intermediate python coding expertise required priority: high should be done before next release type: bug something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants