栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Matplotlib:缩放后找出xlim和ylim

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Matplotlib:缩放后找出xlim和ylim

matplotlib有一个事件处理API,您可以使用它来挂接您所指代的操作。“事件处理”页面提供了事件API的概述,并且在“轴”页面上(非常)简短地提到了x和y极限事件。

Axes
实例通过作为实例的callbacks属性支持回调
CallbackRegistry
。您可以连接的事件为
xlim_changed
ylim_changed
并且回调将在实例
func(ax)
所在的位置调用。
ax``Axes

在您的方案中,您想在

Axes
对象的
xlim_changed
ylim_changed
事件上注册回调函数。每当用户缩放或移动视口时,将调用这些函数。

这是一个最小的工作示例:

Python 2

import matplotlib.pyplot as plt## Some toy datax_seq = [x / 100.0 for x in xrange(1, 100)]y_seq = [x**2 for x in x_seq]## Scatter plotfig, ax = plt.subplots(1, 1)ax.scatter(x_seq, y_seq)## Declare and register callbacksdef on_xlims_change(event_ax):    print "updated xlims: ", event_ax.get_xlim()def on_ylims_change(event_ax):    print "updated ylims: ", event_ax.get_ylim()ax.callbacks.connect('xlim_changed', on_xlims_change)ax.callbacks.connect('ylim_changed', on_ylims_change)## Showplt.show()

Python 3

import matplotlib.pyplot as plt## Some toy datax_seq = [x / 100.0 for x in range(1, 100)]y_seq = [x**2 for x in x_seq]## Scatter plotfig, ax = plt.subplots(1, 1)ax.scatter(x_seq, y_seq)## Declare and register callbacksdef on_xlims_change(event_ax):    print("updated xlims: ", event_ax.get_xlim())def on_ylims_change(event_ax):    print("updated ylims: ", event_ax.get_ylim())ax.callbacks.connect('xlim_changed', on_xlims_change)ax.callbacks.connect('ylim_changed', on_ylims_change)## Showplt.show()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/596361.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号