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

Fix double visualization issues #53

Open
martingarridorc opened this issue Sep 16, 2024 · 6 comments
Open

Fix double visualization issues #53

martingarridorc opened this issue Sep 16, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@martingarridorc
Copy link
Member

Some plots appear repeated on the Jupyter notebooks executions. To be fixed and tested in at least 2 computers.

@ivanovaos
Copy link
Member

ivanovaos commented Sep 16, 2024

This is a known bug/feature caused by behaviour of jupyter with matplotlib. Whenever the plot() is called, jupyter renders it. If the function returns the plot too, jupyter will render it 2nd time. We return the plot if the user wants to adjust it or play around with it themselves.

The fastest and easiest fix for this would be to assign a variable before calling the plot. This will still make it render in jupyter but prevents it from doing it twice. There are several other options, but they are not really good for various reasons. E.g. closing the plot in the function - it will affect the behaviour outside of jupyter on linux platforms. Setting the matplotlib to inline within jupyter
%matplotlib inline
it works only if the plot is not returned by the function and not on all versions of jupyter.

The setup for every plotting function for jupyter run (adding bool param to the function in_jupyter) - not desirable as it increases params set for every single function in vis.

@deeenes
Copy link
Member

deeenes commented Sep 16, 2024

What if we check whether the code runs in Jupyter notebook? Does this happen also with the object oriented matplotlib api? What's the main difference between the code that emits Jupyter widget when calling plot vs. the one that doesn't?

@ivanovaos
Copy link
Member

It is possible to check, yes, via env var, and return the fig conditionally to it.
I'd say whoever is using jupyter with matplotlib is probably already aware of the issue, and we could simply document it.

Does this happen also with the object oriented matplotlib api?

Not sure what you mean here.

What's the main difference between the code that emits Jupyter widget when calling plot vs. the one that doesn't?

Jupyter calls figure rendering automatically. If I don't return figure from the function, the behaviour is not observed in my env.

There are 3 use cases of our API: jupyter, vanilla python plotting interface, and operating on the plotting function output to e.g. adjust styling. Depending on the priority we give for each, this can be solved differently. My perspective is that jupyter is not the main priority/use case, so the fix should be rather on the side of jupyter than in python code.

@ivanovaos
Copy link
Member

For now fixed with var assignement. Updated with conditional on jup env, will submit after merge dev to main, since all vignettes will be affected.

@ivanovaos
Copy link
Member

currently the fix is at 5c7d288

@deeenes
Copy link
Member

deeenes commented Sep 17, 2024

To make it more precise, what about:

'ZMQ' in get_ipython().__class__.__name__

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants