如何将plt中的x,y更改为cartopy中的lon,lat?

发布于 2025-01-17 05:39:25 字数 1181 浏览 1 评论 0原文

在此处输入图像描述 当我单击地图中的某个点并获取 x,y 时,我想将 x,y 更改为 lon,lat (黄色标记下方的图片)。 我怎样才能改变它?请帮助我...

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
import cartopy

def mouse_click(event):
    x, y = event.xdata, event.ydata
    print(x, y)

proj = ccrs.LambertConformal(central_longitude=125, central_latitude=35, false_easting=400000,false_northing=400000,
                                 standard_parallels=(46, 49))

fig = plt.figure(figsize=(16.535433, 11.692913))
ax = fig.add_subplot(1,1,1, projection=proj)
ax.set_extent((79, 156, 10, 66))
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, linewidth=0.2,color='black', alpha=0.5,
                  linestyle=(3, (20, 5)), xlocs=np.arange(-180, 200, 10), x_inline=False, y_inline=False)
                  #xlabel_style = {'rotation': 0},ylabel_style = {'rotation': 0})

ax.coastlines(resolution='50m', alpha=1, linewidth=0.5)
ax.add_feature(cartopy.feature.BORDERS, alpha=1,linewidth=0.5)  
ax.add_feature(cartopy.feature.LAKES, alpha=0.4)  
plt.connect('button_press_event', mouse_click)
plt.show()

我试图找到它,但很难理解。

enter image description here
I want to change x, y to lon, lat (Picture below yellow marker) when I click some point in map and get x, y.
How can I change it? Help me please...

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
import cartopy

def mouse_click(event):
    x, y = event.xdata, event.ydata
    print(x, y)

proj = ccrs.LambertConformal(central_longitude=125, central_latitude=35, false_easting=400000,false_northing=400000,
                                 standard_parallels=(46, 49))

fig = plt.figure(figsize=(16.535433, 11.692913))
ax = fig.add_subplot(1,1,1, projection=proj)
ax.set_extent((79, 156, 10, 66))
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, linewidth=0.2,color='black', alpha=0.5,
                  linestyle=(3, (20, 5)), xlocs=np.arange(-180, 200, 10), x_inline=False, y_inline=False)
                  #xlabel_style = {'rotation': 0},ylabel_style = {'rotation': 0})

ax.coastlines(resolution='50m', alpha=1, linewidth=0.5)
ax.add_feature(cartopy.feature.BORDERS, alpha=1,linewidth=0.5)  
ax.add_feature(cartopy.feature.LAKES, alpha=0.4)  
plt.connect('button_press_event', mouse_click)
plt.show()

I tried to find about it but It's hard to understanding.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百善笑为先 2025-01-24 05:39:25

我找到了一些办法。
改变投影。

fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1], projection=ccrs.PlateCarree())
ax.add_feature(cartopy.feature.LAND, facecolor='black')
ax.set_global()

在兰伯特共形中,x,y 与 lon,lat 不同。但在 PlateCarree 中,它们是相同的。

I found some way.
Change the projection.

fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1], projection=ccrs.PlateCarree())
ax.add_feature(cartopy.feature.LAND, facecolor='black')
ax.set_global()

In LambertConformal,x,y is different with lon,lat. But in PlateCarree, they are same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文