matplotlib / matplotlib/ipympl

Memory leak

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

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

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
Plotting a 30M row data frame causes memory only to increase. Also memory isn't collected by `gc.collect`.
As discussed with matplotlib guys in https://github.com/matplotlib/matplotlib/issues/21259 (and Jupyter guys: https://github.com/jupyterlab/jupyterlab/issues/11182) - we tested and it works as intended. I tested further and think I found the issue - `%matplotlib widget`:
```python
%matplotlib widget # if this is commented out, gc.collect releases the memory

import gc

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

zeros = pd.Series(np.zeros(30_000_000))
df = pd.concat([zeros, zeros, zeros, zeros], axis=1)

FROM = 0
TO = 10_000_000 # df.shape[0]
color_spread = "grey"

fig, axs = plt.subplots(1, 1, sharex=True)

ax2 = axs.twinx()
ax2.plot(df[df.columns[0]][FROM:TO], color="blue")
ax2.plot(df[df.columns[1]][FROM:TO], color="red")
ax2.tick_params(axis="y", labelcolor="red")

ax1 = axs.twinx()
ax1.plot(df[df.columns[2]][FROM:TO], color="orange")
ax1.plot(df[df.columns[3]][FROM:TO], color="yellow")

fig.tight_layout()
plt.show()
gc.collect()
```

## Versions
```
3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 16:07:37)
[GCC 9.3.0]
ipympl version: 0.7.0
jupyter core : 4.7.1
jupyter-notebook : 6.4.3
qtconsole : not installed
ipython : 7.27.0
ipykernel : 6.4.1
jupyter client : 7.0.2
jupyter lab : 3.1.11
nbconvert : 6.1.0
ipywidgets : 7.6.5
nbformat : 5.1.3
traitlets : 5.1.0
Config option `kernel_spec_manager_class` not recognized by `ListNBExtensionsApp`.
Known nbextensions:
config dir: /home/test/PROGS/miniconda3/envs/puma-lab/etc/jupyter/nbconfig
notebook section
jupyter-matplotlib/extension enabled
- Validating: OK
nbdime/index 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 option `kernel_spec_manager_class` not recognized by `ListLabExtensionsApp`.
[W 2021-10-07 12:20:00.836 LabApp] Config option `kernel_spec_manager_class` not recognized by `LabApp`.
JupyterLab v3.1.11
/home/test/PROGS/miniconda3/envs/puma-lab/share/jupyter/labextensions
jupyter-matplotlib v0.9.0 enabled OK
nbdime-jupyterlab v2.1.0 enabled OK
@jupyterlab/git v0.32.2 enabled OK (python, jupyterlab-git)
@pyviz/jupyterlab_pyviz v2.1.0 enabled OK (python, pyviz_comms)
@jupyter-widgets/jupyterlab-manager v3.0.1 enabled OK (python, jupyterlab_widgets)

Other labextensions (built into JupyterLab)
app dir: /home/test/PROGS/miniconda3/envs/puma-lab/share/jupyter/lab

```

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

Start with the supplied minimal reproducer in a Jupyter notebook, comparing memory behavior with `%matplotlib widget` enabled and commented out. Investigate the ipympl widget integration and verify that after plotting and calling `gc.collect()`, the data frame and plot memory are released as expected.

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-notebook, python
Lĩnh vực
backend, frontend
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 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
25/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.