【问题标题】:background image interpolation with caryopy背景图像插值与 caryopy
【发布时间】:2020-10-14 20:41:22
【问题描述】:

最近我在 python 3.8 上更新到 matplotlib 3.3.1。我使用 cartopy 0.18.0 版。在这个版本中,背景图像插值似乎不再起作用。有没有人有解决方法/解决方案? 这是一个最小的可重现示例:

import matplotlib.pyplot as plt
import cartopy as ccrs
import cartopy.io.img_tiles as cimgt

fig, ax = plt.subplots(subplot_kw=dict(projection=ccrs.crs.PlateCarree()))
ax.set_extent([67, 75, 20, 26])
ax.add_image(cimgt.GoogleTiles(), 8, interpolation='spline36')

这会引发错误:

TypeError:得到了一个意外的关键字参数“插值”

【问题讨论】:

  • 你想要的结果是什么? cartopy 的哪个版本支持 cartopy.mpl.geoaxes.GeoAxes.add_image 的“插值”参数? add_image 当前不允许任何 args 或 kwargs github.com/SciTools/cartopy/blob/…
  • 我使用相同版本的 cartopy,但在 python 3.6 上使用 matplotlib 3.1。我需要插值以获得更好看的地图。例如,请参阅stackoverflow.com/questions/49155110/…

标签: python matplotlib cartopy


【解决方案1】:

如果您需要更高分辨率的图像,则需要增加scale 的值。在您的代码中,您可以将 8 更改为 10 作为新实验。

ax.add_image(cimgt.GoogleTiles(), 10)

编辑1

由于使用了与原始(crs.Mercator())不同的投影(crs.PlateCarree()),导致图像在渲染时重新投影,导致图像质量不理想。而这种带有锐利边缘/线条、符号和文本的图像,很难通过重投影或插值得到好的结果。让我们使用原始投影来绘制地图并研究结果。

import matplotlib.pyplot as plt
import cartopy as ccrs
import cartopy.io.img_tiles as cimgt

tiles = cimgt.GoogleTiles()
image_crs = tiles.crs

fig, ax = plt.subplots(figsize=(16,12), subplot_kw=dict(projection=image_crs))

ax.set_extent([67, 75, 20, 26], crs=ccrs.crs.PlateCarree())

ax.add_image(cimgt.GoogleTiles(), 8)
plt.show()

输出图:

【讨论】:

  • 感谢您指出这一点。然而,比例参数只是增加了更多细节,但地图质量并没有提高。请参阅github.com/SciTools/cartopy/issues/1048 的讨论
  • @VinodKumar 新方法是否提供了更好的图像质量?
  • 这确实提高了图像质量,但我不想跳过投影(crs.PlateCarree())。这是在地图上添加更多数据叠加层所必需的。
  • 如果其他数据覆盖是矢量,则 web-mercator 投影没有问题。只有某些类型的栅格数据在重新投影时会失败。
猜你喜欢
  • 2022-07-21
  • 2019-11-26
  • 1970-01-01
  • 2017-07-19
  • 2010-12-09
  • 1970-01-01
  • 1970-01-01
  • 2011-11-10
  • 1970-01-01
相关资源
最近更新 更多