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

Widget is shown once. After that a text representation is shown #302

Closed
bgbg opened this issue Feb 23, 2021 · 1 comment
Closed

Widget is shown once. After that a text representation is shown #302

bgbg opened this issue Feb 23, 2021 · 1 comment

Comments

@bgbg
Copy link

bgbg commented Feb 23, 2021

What I do:

  1. In Jupyter notebook, specify %matplotlib
  2. Create a plot -> works OK
  3. Rerun the cell, or create another one -> we see a text representation.

The only thing that fixes the problem is kernel restart

Here's a video recording https://cloudup.com/c5e24HCaLI6

python -c "import sys; print('\n',sys.version); import ipympl; print('ipympl version:', ipympl.__version__)" && jupyter --version && jupyter nbextension list && jupyter labextension list

-->

python -c "import sys; print('\n',sys.version); import ipympl; print('ipympl version:', ipympl.__version__)" && jupyter --version && jupyter nbextension list && jupyter labextension list


 3.8.5 (default, Sep  4 2020, 02:22:02)
[Clang 10.0.0 ]
ipympl version: 0.6.3
jupyter core     : 4.6.3
jupyter-notebook : 6.2.0
qtconsole        : 4.7.7
ipython          : 7.20.0
ipykernel        : 5.3.4
jupyter client   : 6.1.7
jupyter lab      : 3.0.0
nbconvert        : 6.0.7
ipywidgets       : 7.5.1
nbformat         : 5.0.8
traitlets        : 5.0.5
Known nbextensions:
  config dir: /Users/boris/.jupyter/nbconfig
    notebook section
      execute_time/ExecuteTime  enabled
      - Validating: OK
      splitcell/splitcell disabled
      jupyter-js-widgets/extension  enabled
      - Validating: OK
      toc2/main  enabled
      - Validating: OK
      snippets_menu/main disabled
      collapsible_headings/main  enabled
      - Validating: OK
      export_embedded/main  enabled
      - Validating: OK
      codefolding/main  enabled
      - Validating: OK
      python-markdown/main  enabled
      - Validating: OK
      notify/notify  enabled
      - Validating: OK
      hide_input/main  enabled
      - Validating: OK
      code_prettify/autopep8  enabled
      - Validating: OK
      toggle_all_line_numbers/main disabled
      hide_header/main  enabled
      - Validating: OK
      autosavetime/main  enabled
      - Validating: OK
      snippets/main disabled
      hide_input_all/main  enabled
      - Validating: OK
      code_font_size/code_font_size disabled
      voila/extension disabled
      contrib_nbextensions_help_item/main disabled
      gist_it/main disabled
    edit section
      codefolding/edit  enabled
      - Validating: OK
  config dir: /Users/boris/opt/anaconda3/etc/jupyter/nbconfig
    notebook section
      itkwidgets/extension  enabled
      - Validating: OK
      jupyter-datawidgets/extension  enabled
      - Validating: OK
      jupyter-matplotlib/extension  enabled
      - Validating: OK
      plotlywidget/extension  enabled
      - Validating: OK
      jupyter-js-widgets/extension  enabled
      - Validating: OK
      nbextensions_configurator/config_menu/main  enabled
      - Validating: problems found:
        - require?  X nbextensions_configurator/config_menu/main
      contrib_nbextensions_help_item/main  enabled
      - Validating: OK
    tree section
      nbextensions_configurator/tree_tab/main  enabled
      - Validating: problems found:
        - require?  X nbextensions_configurator/tree_tab/main
JupyterLab v3.0.0
/Users/boris/opt/anaconda3/share/jupyter/labextensions
        jupyter-matplotlib v0.8.3 enabled OK
        jupyterlab-datawidgets v7.0.0 enabled OK
        jupyterlab-execute-time v2.0.1 enabled OK (python, jupyterlab_execute_time)

Other labextensions (built into JupyterLab)
   app dir: /Users/boris/opt/anaconda3/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v3.0.0 enabled OK
        @jupyterlab/apputils v3.0.5 enabled OK
@thomasaarholt
Copy link
Contributor

Hi @bgbg, thanks for the recording, that's neat.

The problem you're describing is actually intentional behaviour. It's been raised before in separate issues (#60 and #4). On the first call, matplotlib recognises that there doesn't exist a figure object, so it creates one. On the second call, despite not being shown, the figure still exists, so plot() adds to that figure, but also doesn't return any output.

The solution is to do:

plt.figure()
plt.plot()
# or
fig, ax = plt.subplots()
ax.plot()

The reason for this problem is that we currently don't communicate back to python that when the cell output is overwritten, the figure should be closed (this is hard).

There are good reasons for this, since one sometimes wants to create figure, but show it later.

@bgbg bgbg closed this as completed Mar 5, 2021
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