更改状态栏中坐标文本的格式 [英] Change format of coordinate text in status bar

查看:45
本文介绍了更改状态栏中坐标文本的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

解决方案

您可以为轴重新分配 format_coord 方法,如以下示例所示(改编自

Does anyone know how to modify the "x" and "y" in the status bar below a plot?

I want to change it to "Longitude" and "Latitude", is it possible in matplotlib?

解决方案

You can re-assign the format_coord method of your Axes, as in the following example (adapted from here and 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()

Or, in a one-liner, you could use a lambda function:

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

这篇关于更改状态栏中坐标文本的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆