matplotlib / matplotlib/ipympl

Matplotlib Fails to Update Axis Limits with ipywidgets in Jupyter Lab

Đang mở
#551 1 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ả

I'm using `ipywidgets` along with `matplotlib` in Jupyter Lab and stumbled across some strange behavior. Here's an example of the code:

```python
import matplotlib.pyplot as plt
import ipywidgets as widgets
%matplotlib widget
plt.ioff()

d = {
"a": [1,2,3],
"b": [2,3,4]
}

fig, ax = plt.subplots()

def update(change):
data = d[change["new"]]
ax.clear() # Clear the previous plot
ax.plot(data, data)
ax.set_xlim(min(data), max(data))
ax.set_ylim(min(data), max(data))
ax.figure.canvas.draw()

dropdown = widgets.Dropdown(options = list(d.keys()))
dropdown.observe(update, "value")

display(dropdown, fig.canvas)
update({"new": "a"})
```

The steps I carry out are as follows:

- Select `b` from dropdown
- Pan the plot
- Select `a` from dropdown
- Click on the "Reset original view" button on the plot

Instead of snapping the plot extents back to what they are set for choice `a`, I instead get the following:

[![enter image description here][1]][1]

Where it looks like `matplotlib` has indeed plotted the data `[1,2,3]`, but somehow failed to update the axis limits based on that data.

I really hope this isn't a bug, and that I'm doing something wrong. Has anyone seen this behavior before?

[1]: https://i.stack.imgur.com/nCOHG.png

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 reproducer Jupyter Lab trong issue với dropdown của ipywidgets và widget backend của Matplotlib, sau đó thực hiện theo chuỗi thao tác chọn, pan và reset được liệt kê. So sánh các giới hạn trục được khôi phục với các giới hạn được đặt cho từng dataset; được xem là hoàn tất khi, sau khi chuyển từ b sang a, chế độ xem đã reset khớp với dữ liệu hiện được chọn.

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
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
40/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.