首页 > 解决方案 > 从 cartopy 生成的图像图中获取显示协调

问题描述

我需要在地图上绘制点,在该地图上生成 PNG 图像,并输出与绘制点协调的显示。

使用 cartopy 我可以得到我想要的地图并在给定的 lon/lat 坐标中绘制一个点。

我无法弄清楚如何获取像素坐标。我尝试遵循简单的 matplotlib 教程https://matplotlib.org/users/transforms_tutorial.html 但在这种情况下它不能按预期工作

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

# Create Mercator projection with dateline in the middle:
from matplotlib import lines

fig = plt.figure(figsize=(10, 10))
ax = plt.axes(projection=ccrs.Mercator(central_longitude=26,))
ax.set_extent([19, 33, 59.5, 70.5], crs=ccrs.PlateCarree())


LAND = cfeature.NaturalEarthFeature('physical', 'land', '50m',
                                    edgecolor='face',
                                    facecolor=cfeature.COLORS['land'], zorder=-1)

ax.add_feature(LAND)
ax.coastlines(resolution='50m')

ax.add_feature(cfeature.NaturalEarthFeature('cultural', 'admin_0_boundary_lines_land',
                              '50m', edgecolor='black', facecolor='none'))


plt.plot([26.7042], [60.8679],  color='blue', linewidth=2, marker='o',
         transform=ccrs.PlateCarree(),
         )

fig.canvas.draw()
# print image x y coordinates of point 60.8679° N, 26.7042° E here

plt.show()

在此处输入图像描述

标签: pythonmatplotlibcartopy

解决方案


推荐阅读