python坐标网matplotlib,matplotlib自定义鼠标光标坐标格式的实现

matplotlib默认在图像Windows窗口中显示当前鼠标光标所在位置的坐标,格式为x=xx, y=xx。

鼠标光标的坐标格式由子图模块Axes中的format_coord函数控制。

通过重写format_coord函数即可实现坐标的自定义格式。

注意:调用format_coord函数的对象是子图对象,常见的错误主要在没有正确的获取当前子图对象。

a12832ff6136e48f9873a7e254ab9d22.png

format_coord函数源码

matplotlib.axes.Axes.format_coord

def format_coord(self, x, y):

"""Return a format string formatting the *x*, *y* coordinates."""

if x is None:

xs = '???'

else:

xs = self.format_xdata(x)

if y is None:

ys = '???'

else:

ys = self.format_ydata(y)

return 'x=%s y=%s' % (xs, ys)

自定义坐标格式实现

import matplotlib.pyplot as plt

def format_coord(x, y):

return 'x坐标为%1.4f, y坐标为%1.4f' % (x, y)

#获取当前子图

ax=plt.gca()

ax.format_coord = format_coord

plt.show()

b766bdc9cd2d7d1939a3acfd5a003ec3.png

到此这篇关于matplotlib自定义鼠标光标坐标格式的实现的文章就介绍到这了,更多相关matplotlib自定义鼠标光标坐标内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值