【问题标题】:Change format of coordinate text in status bar更改状态栏中坐标文本的格式
【发布时间】:2016-06-15 11:45:01
【问题描述】:

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

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

【问题讨论】:

标签: python python-2.7 matplotlib


【解决方案1】:

您可以重新分配 Axes 的 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)

【讨论】:

  • 天哪!这么好的答案,它对我的​​论文很有帮助。非常感谢汤姆先生
  • 是的,我想是的。查看链接的帖子
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-28
  • 2017-12-13
  • 2019-10-27
  • 2019-12-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多