Plots appear twice in notebooks

See original GitHub issue

Every call to a plotting function produces two plots in a notebook, e.g.:

Screen Shot 2022-09-15 at 15 16 29

This is because our functions return the figure, which then automatically gets plotted in a notebook. In addition, we also see the plot which is explicitly produced by the function.

I don’t think _ = XXXX.plot() or XXXX.plot(); are good solutions (pretty ugly). The only way this works nicely is XXXX.plot(show=False).

Could we somehow fix this weird behavior? By weird I mean (1) there are either two figures (show=True) or (2) there is one figure but show=False sounds like there should be none.

What about setting show=False by default only in a notebook environment?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:40 (40 by maintainers)

github_iconTop GitHub Comments

2reactions
cbrnrcommented, Sep 15, 2022

I think we are at least partly to blame. If you do

import matplotlib.pyplot as plt
plt.plot(1)

in a notebook, you only see the figure once, because the plotting function does not return the figure, but some sort of line collection. This is also what they recommend (plot does not return a Figure), so I think it’s also the returning a Figure part that’s causing this issue specifically.

Screen Shot 2022-09-15 at 15 44 19
1reaction
hoechenbergercommented, Nov 1, 2022

Just for reference, this problem was previously discussed here: https://github.com/mne-tools/mne-python/issues/8424

Haha it’s kinda funny to see how the perception of what is and what is not correct behavior has changed over the past two years 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is Jupyter showing charts twice? - python - Stack Overflow
It's working, but every time I plot a chart, the chart shows up twice. The first two charts in my notebook are plotted...
Read more >
Duplicate Plots, notebook displays twice · Issue #1265 - GitHub
Display is up to the user. The problem is an ipython setting that displays it automatically (twice).
Read more >
Any way to repeat a plot? : r/IPython - Reddit
I'm working on a slide show using an IPython notebook where I have a complicated plot created on one slide. But I would...
Read more >
Matplotlib graphs are being duplicated each time
I have the issue that anything I plot appears twice. I am not sure why this is happening, so I am looking for...
Read more >
About Jupyter Notebooks - AHA - Precision Medicine Platform
... Pretty Display of Variables; Easy links to documentation; Plotting in notebooks ... D + D (press the key twice) to delete the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found