更改状态b中坐标文本的格式

2024-04-23 20:34:26 发布

您现在位置:Python中文网/ 问答频道 /正文

有人知道如何修改绘图下方状态栏中的“x”和“y”吗?在

我想把它改成“经度”和“纬度”,在matplotlib中可以吗?在

enter image description here


Tags: 绘图matplotlib状态栏纬度经度
1条回答
网友
1楼 · 发布于 2024-04-23 20:34:26

可以重新指定轴的format_coord方法,如下例所示(改编自herehere):

import matplotlib.pyplot as plt
import numpy as np

fig,ax = plt.subplots(1)

ax.pcolormesh(np.random.rand(20,20))

def format_coord(x, y):
    return 'Longitude={:6.3f}, Latitude={:6.3f}'.format(x, y)

ax.format_coord = format_coord

plt.show()

或者,在一行代码中,您可以使用lambda函数:

^{pr2}$

enter image description here

相关问题 更多 >