金狮镖局 Design By www.egabc.com

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

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

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

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

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

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 = '"htmlcode">
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()

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

标签:
matplotlib自定义鼠标坐标,matplotlib自定义鼠标光标

金狮镖局 Design By www.egabc.com
金狮镖局 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金狮镖局 Design By www.egabc.com

评论“matplotlib自定义鼠标光标坐标格式的实现”

暂无matplotlib自定义鼠标光标坐标格式的实现的评论...