Flawed PDF save when using linewidth=0 in drawparallels() and drawmeridians()

Đang mở
#493 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.

Đánh giá

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

Hướng nghiên cứu

Bắt đầu bằng cách chạy ví dụ tối thiểu và kiểm tra các điểm vào drawparallels() và drawmeridians() liên quan đến đầu ra PDF. So sánh PDF được tạo trong các trình xem bị ảnh hưởng và xác nhận rằng việc sử dụng linewidth=0 không còn tạo ra kết xuất lỗi, trong khi các đường lưới vẫn được ẩn.

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

Mô tả

Hi all,

I noticed that when saving a basemap plot to a PDF file, the file is flawed when the code has
drawparallels(..., linewidth=0) or drawmerdians(..., linewidth=0) in it.

A minimal working example:

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

figure=plt.figure(figsize=(14,7),dpi=100)
for ii in range(4):
    axii=figure.add_subplot(2,2,ii+1)
    m = Basemap(projection='cyl',
            llcrnrlat=40,urcrnrlat=47,\
            llcrnrlon=-72,urcrnrlon=-67,resolution='l',
            ax=axii, fix_aspect=False)
    m.drawcoastlines()

    lat_ticks=np.arange(41, 47)
    lon_ticks=np.arange(-72, -67)
    m.drawparallels(lat_ticks,labels=[1,0,0,0],linewidth=0)
    m.drawmeridians(lon_ticks,labels=[0,0,0,1],linewidth=0)

figure.savefig('test.pdf')

The PDF won't display correctly in some PDF viewers, for instance Xreader (v.2.4.4) or Adobe reader. But works fine in others, like Okular or Foxit reader. When compiling a LaTeX document using pdflatex, the page containing that figure won't display properly, again it is PDF viewer dependent.

Here is a screenshot of the PDF file opened in Xreader:

Screenshot from 2020-06-07 16-45-02

Here is the same file opened in Okular:

Screenshot from 2020-06-07 16-45-28

The reason for setting linewidth=0 is to remove those grid lines, one relevant questions on Stackoverflow.

One workaround I found is to use zorder=-2 to hide those grid lines while avoiding creating corrupted PDF files.

Note that I've tried a few different matplotlib backends, including Qt5Agg, TkAgg, Agg, and the results are all the same.

Some specs and package versions:
OS: Manjaro Linux
Python = 2.7 or 3.7, in an anaconda env
basemap = 1.2.0
matplotlib = 3.1.3 (for py3) and 1.2.0 (for py2)

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

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.

Issue khác của matplotlib/basemap

Tất cả issue của matplotlib/basemap

Issue tương tự

Thêm issue về Python

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.