matplotlib / matplotlib/ipympl

Re-executing a cell hides the figure when it is given a `num=...` argument

Đang mở
#405 8 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug
Ngôn ngữ chính
Jupyter Notebook
Star
1.7k
Fork
234
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Describe the issue

Explicit figure numbers seem to cause a small glitch in ipympl. When the following cell is executed once, it shows the plot. When re-executing the cell, it disappears again.

x = np.linspace(-np.pi/2, np.pi/2)
plt.figure(num=1)
plt.plot(x, np.sin(x))

I've attached a working example: repeat_plot_issue.zip

The inline and notebook backends do not have this issue, which leads me to believe this is a bug. There are two workarounds:

  1. Close the figure in the beginning of the cell with e.g. plt.close(1)
  2. Show the figure at the end of the cell with plt.show()

(I'm using Jupyter notebooks with a group of about 40 students, and they got confused by this difference in behavior between the backends. I understand this is not a major issue because there are simple workarounds. Still, for newcomers, it is an extra difficulty: "Help, my plot has disappeared!")

Versions

 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:20:46) 
[GCC 9.4.0]
ipympl version: 0.8.2
Selected Jupyter core packages...
IPython          : 7.30.1
ipykernel        : 6.6.0
ipywidgets       : 7.6.5
jupyter_client   : 6.1.12
jupyter_core     : 4.9.1
jupyter_server   : 1.13.1
jupyterlab       : 3.2.5
nbclient         : 0.5.9
nbconvert        : 6.3.0
nbformat         : 5.1.3
notebook         : 6.4.6
qtconsole        : not installed
traitlets        : 5.1.1
Known nbextensions:
  config dir: /home/toon/.jupyter/nbconfig
    notebook section
      splitcell/splitcell disabled
      nbextensions_configurator/config_menu/main  enabled 
      - Validating: problems found:
        - require?  X nbextensions_configurator/config_menu/main
      contrib_nbextensions_help_item/main  enabled 
      - Validating: OK
      spellchecker/main  enabled 
      - Validating: OK
      toc2/main  enabled 
      - Validating: OK
      k3d/extension  enabled 
      - Validating: OK
    tree section
      nbextensions_configurator/tree_tab/main  enabled 
      - Validating: problems found:
        - require?  X nbextensions_configurator/tree_tab/main
  config dir: /home/toon/.local/etc/jupyter/nbconfig
    notebook section
      nbdime/index  enabled 
      - Validating: problems found:
        - require?  X nbdime/index
      rise/main  enabled 
      - Validating: OK
  config dir: /home/toon/miniconda3/envs/py4sci/etc/jupyter/nbconfig
    notebook section
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      rise/main  enabled 
      - Validating: OK
      voila/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
  config dir: /etc/jupyter/nbconfig
    notebook section
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
JupyterLab v3.2.5
/home/toon/miniconda3/envs/py4sci/share/jupyter/labextensions
        k3d v2.11.0 enabled OK (python, k3d)
        jupyter-matplotlib v0.10.2 enabled OK
        @jupyter-widgets/jupyterlab-manager v3.0.1 enabled OK (python, jupyterlab_widgets)
        @ijmbarr/jupyterlab_spellchecker v0.7.2 enabled OK (python, jupyterlab-spellchecker)
        @ryantam626/jupyterlab_code_formatter v1.4.10 enabled OK (python, jupyterlab-code-formatter)
        @voila-dashboards/jupyterlab-preview v2.1.0 enabled OK (python, voila)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách chạy ví dụ repeat_plot_issue.zip được đính kèm với backend ipympl và so sánh với các backend inline và notebook. Việc thực thi lặp lại ô chứa plt.figure(num=1) phải giữ cho hình vẫn hiển thị mà không yêu cầu plt.close(1) hoặc plt.show().

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
jupyter, jupyter-notebook, python
Lĩnh vực
data-visualization, frontend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.