【发布时间】:2016-06-15 11:45:01
【问题描述】:
有谁知道如何修改绘图下方状态栏中的“x”和“y”?
我想把它改成“经度”和“纬度”,在matplotlib中可以吗?
【问题讨论】:
标签: python python-2.7 matplotlib
有谁知道如何修改绘图下方状态栏中的“x”和“y”?
我想把它改成“经度”和“纬度”,在matplotlib中可以吗?
【问题讨论】:
标签: python python-2.7 matplotlib
您可以重新分配 Axes 的 format_coord 方法,如下例所示(改编自 here 和 here):
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)
【讨论】: