python - 从 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()
解决方案
推荐阅读
- python - 在 Windows 下将 Python 嵌入到 C 中
- c++ - 将 lambda 作为参数传递时,gcc 无法扩展宏?- gcc 错误
- c# - WebDriver.SwitchTo().Window() 和 WebDriver.SwitchTo().Frame() 有什么区别
- .htaccess - 强制站点范围的 HTTPS,但在特定目录中强制 HTTP
- python - Python3:os.path.isdir(path) 对文件为 True
- javascript - Unable to create ListItems with 'Objects' using Microsoft Graph Api
- python - RNA拼接Python(未给出输出)
- php - Php Null 合并运算符
- java - 如何禁用嵌套 JPanel 的子组件但保持面板本身可用
- c++ - 定义子类 (c++)