matplotlib / matplotlib/basemap

Bug in contour x/y values filtering in mpl_toolkits/basemap/__init__.py ?

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

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

Ngôn ngữ chính
Python
Star
817
Fork
395
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I have been trying to plot unstructured data with **contour** and **contourf**, using the **tri=True** parameter. It works fine with contourf, but **I get a huge traceback when using contour** on the same data.

```
[...]
File "/home/share/unix_files/cdat/versions/cdat_install_uv-2.1.0_x86_64_gcc4_13/lib/python2.7/site-packages/matplotlib-1.4.0-py2.7-linux-x86_64.egg/matplotlib/tri/triangulation.py", line 55, in __init__
self.triangles, self._neighbors = _qhull.delaunay(x, y)
ValueError: x and y arrays must have a length of at least 3
```

After spending some time in the python debugger, I have found out that indeed the x and y coordinate arrays passed to the triangulation function had a zero size (and therefore less than 3 elements) because they were empty! More digging helped me find a very suspicious way of filtering the x and y values in the contour(self,x,y,data,_args,_*kwargs) function

```
# for unstructured grids, toss out points outside
# projection limb (don't use those points in triangulation).
[...]
mask = np.logical_or(xself.xmax,y>self.xmax)
x = np.compress(mask,x)
y = np.compress(mask,y)
```

Why would y be compared to the values of xmin and xmax instead of ymin and ymax, and is the logical combination ok???

I think we want to keep the values where: **xmin<=x<=xmax AND ymin<=y<=ymax**. And the **mask has to be True where we want to keep the value, in np.compress**! This is a bit misleading because it works in the opposite way that masks work in np.ma ...

The contour function works fine if I replace the mask definition above with

```
mask = np.logical_and(np.logical_and(x>=self.xmin, x<=self.xmax),
np.logical_and(y>=self.ymin, y<=self.ymax))
```

Can somebody review this? And it may be wise to use a slightly less misleading name for the _mask_ variable. Maybe replace _mask_ with _select_xy_ok_?

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

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

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 trong mpl_toolkits/basemap/__init__.py, tại logic lọc của contour(self, x, y, data, ...), sau đó so sánh các đầu vào của nó với matplotlib.tri triangulation traceback. Xem xét việc lọc theo giới hạn tọa độ được đề xuất và chạy các kiểm thử contour hoặc contourf hiện có nếu có. Hoàn tất khi contour xử lý dữ liệu không có cấu trúc được báo cáo mà không truyền các mảng tọa độ rỗng cho phép tam giác hóa.

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

Đánh giá

Công nghệ
numpy, python
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả 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.