matplotlib / matplotlib/basemap

[Bug]: Basemap drawgreatcircle generating gaps in Mercator projection

Đang mở
#606 3 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
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ả

Bug summary

I see an issue where drawgreatcircle() produces paths with gaps in with the Mercator projection.

I can see from web searches that others have seen the same issue and suggestions point to gathering the path using computations with other projections.

Code for reproduction
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt

# setup mercator map projection.
m = Basemap(llcrnrlon=-180.,llcrnrlat=-65.,\
            urcrnrlon=180.,urcrnrlat=85.,\
            projection='merc',\
            lat_0=40.,lon_0=-20.,lat_ts=20.)
m.drawcoastlines()
m.fillcontinents()

# AMS
amslat = np.float64(52.309)
amslon = np.float64(4.764)
# Seattle
sealat = np.float64(47.449)
sealon = np.float64(-122.309)
# Helsinki
hellat = np.float64(60.320)
hellon = np.float64(24.956)

m.drawgreatcircle(amslon,amslat,sealon,sealat,linewidth=2,color='b')
m.drawgreatcircle(sealon,sealat,hellon,hellat,linewidth=2,color='b')

# draw parallels
m.drawparallels(np.arange(-60,65,20))
# draw meridians
m.drawmeridians(np.arange(-180,180,30))
plt.show()
Actual outcome

Gaps_times2

Expected outcome

Gaps_times5

Additional information

I don't understand the basemap calculations and how projections enter into it but I can recover the correct output if I change the test for cuts in the source code by making max_dist much larger...

diff -c __init*py.orig **init*py
*** __init__.py.orig    Mon Aug 26 08:40:10 2024
--- __init__.py Mon Aug 26 09:28:34 2024
***************
*** 2901,2907 ****
          p = _p[0].get_path()

          # since we know the difference between any two points, we can use this to find wrap arounds on the plot
!         max_dist = 1000*del_s*2

          # calculate distances and compare with max allowable distance
          dists = np.abs(np.diff(p.vertices[:,0]))
--- 2901,2907 ----
          p = _p[0].get_path()

          # since we know the difference between any two points, we can use this to find wrap arounds on the plot
!         max_dist = 1000*del_s*5

          # calculate distances and compare with max allowable distance
          dists = np.abs(np.diff(p.vertices[:,0]))

This is what I did to generate the output in the expected result box.
It would be helpful if the defaults did allow great circle paths into high lattitudes.

Operating system

Windows 10

Matplotlib Version

3.8.4

Matplotlib Backend

3.8.4

Python version

3.12.2

Jupyter version

No response

Installation

conda

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 init.py, tại logic path-cut của drawgreatcircle gần phép tính max_dist, sau đó chạy bản tái hiện bằng Python với phép chiếu Mercator. Điều tra lý do ngưỡng khoảng cách hiện tại tạo ra các khoảng trống ở vĩ độ cao; được xem là hoàn tất khi hai đường đi theo vòng tròn lớn được render liên tục mà không tạo ra các kết nối wraparound không chính xác.

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

Đánh giá

Công nghệ
matplotlib, numpy, python
Lĩnh vực
data-visualization
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
42/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.