Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用cnmaps时无法产出正确的eps文件 #125

Open
soldierofmushroom opened this issue Jul 3, 2024 · 1 comment
Open

使用cnmaps时无法产出正确的eps文件 #125

soldierofmushroom opened this issue Jul 3, 2024 · 1 comment
Assignees

Comments

@soldierofmushroom
Copy link

soldierofmushroom commented Jul 3, 2024

老师您好,我使用issue97您给出的代码,能够产出正确的eps文件(能用GSview打开,也能用在线网址成功转成png文件),代码如下:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cnmaps import get_adm_maps, clip_contours_by_map, draw_maps, MapPolygon
from cnmaps.sample import load_temp
from shapely.geometry import Polygon

fig = plt.figure(figsize=(6, 5), dpi=300)
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection=ccrs.PlateCarree())
lons, lats, data = load_temp()
cs = ax.contourf(lons, lats, data)

boundary = MapPolygon(
    [Polygon([[70, 55], [140, 55], [140, 40], [70, 40], [70, 55]])]
) & get_adm_maps(country="中华人民共和国", only_polygon=True, record="first")

draw_maps(get_adm_maps(country="中华人民共和国"), ax)
clip_contours_by_map(cs, boundary, ax)
ax.set_extent([70, 140, 40, 55], crs=ccrs.PlateCarree())
fig.savefig(r"d:/desktop/test1.eps", bbox_inches="tight")

正确打开的eps

但当我把绘图的区域向南拓展(上面的代码南边界是北纬40°,我拓展至北纬20°),则无法输出正确的eps文件(png和jpg这类文件还是能正常输出)
代码如下:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cnmaps import get_adm_maps, clip_contours_by_map, draw_maps, MapPolygon
from cnmaps.sample import load_temp
from shapely.geometry import Polygon

fig = plt.figure(figsize=(6, 5), dpi=300)
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection=ccrs.PlateCarree())
lons, lats, data = load_temp()
cs = ax.contourf(lons, lats, data)

boundary = MapPolygon(
    [Polygon([[70, 55], [140, 55], [140, 20], [70, 20], [70, 55]])]
) & get_adm_maps(country="中华人民共和国", only_polygon=True, record="first")

draw_maps(get_adm_maps(country="中华人民共和国"), ax)
clip_contours_by_map(cs, boundary, ax)
ax.set_extent([70, 140, 20, 55], crs=ccrs.PlateCarree())
fig.savefig(r"d:/desktop/test1.eps", bbox_inches="tight")

image
image

GSview给我的信息是这样的,我不知道是否有用,贴出来给您看看:

GSview 5.0 2012-01-17
Unknown in Comments section at line 6:
  %%Orientation: portrait


GPL Ghostscript 9.50 (2019-10-15)
Copyright (C) 2019 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Displaying DSC file D:/desktop/test1.eps without pages
Error: /stackoverflow in /--%ztokenexec_continue--
Operand stack:
   --nostringval--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   false   1   %stopped_push   1990   1   3   %oparray_pop   1989   1   3   %oparray_pop   1977   1   3   %oparray_pop   1833   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:740/1123(ro)(G)--   --dict:0/20(G)--   --dict:80/200(L)--   --dict:8/8(L)--
Current allocation mode is local
Last OS error: No such file or directory

--- Begin offending input ---
5 l

252.072447 32.84414 l

252.066076 32.839663 l

252.064313 32.837363 l

252.065533 32.835734 l

252.06865 32.834785 l

252.070685 32.832479 l

252.071633 32.829359 l

252.071495 32.826787 l

252.069327 32.824892 l

252.065939 32.824211 l

252.063499 32.821634 l

252.062551 32.817843 l

252.059706 32.817162 l

252.055364 32.817705 l

252.051299 32.82123 l

252.050083 32.825027 l

252.047909 32.828009 l

252.044254 32.828147 l

252.041813 32.82869 l

252.033138 32.82666 l

252.027308 32.824625 l

252.021616 32.825305 l

252.015379 32.830595 l

252.013215 32.83412 l

252.014435 32.839674 l

252.01782 32.841033 l

252.022292 32.840491 l

252.025138 32.841301 l

252.027445 32.846722 l

252.031105 32.857841 l

252.033546 32.860552 l

252.03693 32.861905 l

252.051301 32.862715 l

cl

251.264929 33.039879 m

251.261618 33.050222 l

251.264516 33.06801 l

251.273619 33.077529 l

251.284793 33.077949 l

251.30507 33.064296 l

251.314434 33.06115 l

251.327671 33.060269 l

251.337205 33.066801 l

251.326361 33.0951
--- End offending input ---
file offset = 2408739
gsapi_run_string_continue returns -101
@soldierofmushroom
Copy link
Author

补充说明:
image
把白化的那一行注释掉即可产出正确的eps文件

@Clarmy Clarmy self-assigned this Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants