python - 更改状态栏中坐标文本的格式

标签 python python-2.7 matplotlib

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

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

enter image description here

最佳答案

您可以重新分配轴的 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 函数:

ax.format_coord = lambda x, y: "Longitude={:6.3f}, Latitude={:6.3f}".format(x,y)

enter image description here

关于python - 更改状态栏中坐标文本的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35750332/

相关文章:

python - 使用 python 简化有理数

python - 如何在 django rest 框架中保存嵌套关系?

python - 向 matplotlib 图形添加标签

javascript - 将基本的Python游戏嵌入到网络中?

python - 比较两个元组列表

python - PyTorch 内存模型 : "torch.from_numpy()" vs "torch.Tensor()"

zooming - Matplotlib/Pyplot : How to zoom subplots together?

python - 使用Python解析特定时区的日期

python - 如何为共存的 Python 2.7/3.4 设置 pip?

python - 移植涉及 matplotlib 设置轴位置(以像素为单位)的 Matlab 代码