圆月山庄资源网 Design By www.vgjia.com
matplotlib
官方除了提供了鼠标十字光标的示例,还提供了同一图像内多子图共享光标的示例,其功能主要由widgets
模块中的MultiCursor
类提供支持。
MultiCursor
类与Cursor
类参数类似,差异主要在:
Cursor
类参数只有一个ax
,即需要显示光标的子图;MultiCursor
类参数为canvas
和axes
,其中axes
为需要共享光标的子图列表。Cursor
类中,光标默认是十字线;MultiCursor
类中,光标默认为竖线。
官方示例
import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import MultiCursor t = np.arange(0.0, 2.0, 0.01) s1 = np.sin(2*np.pi*t) s2 = np.sin(4*np.pi*t) fig, (ax1, ax2) = plt.subplots(2, sharex=True) ax1.plot(t, s1) ax2.plot(t, s2) multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1) plt.show()
简易修改版
multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1, horizOn=True, vertOn=True)
MultiCursor
类源码
class MultiCursor(Widget): """ Provide a vertical (default) and/or horizontal line cursor shared between multiple axes. For the cursor to remain responsive you must keep a reference to it. Example usage:: from matplotlib.widgets import MultiCursor import matplotlib.pyplot as plt import numpy as np fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True) t = np.arange(0.0, 2.0, 0.01) ax1.plot(t, np.sin(2*np.pi*t)) ax2.plot(t, np.sin(4*np.pi*t)) multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1, horizOn=False, vertOn=True) plt.show() """ def __init__(self, canvas, axes, useblit=True, horizOn=False, vertOn=True, **lineprops): self.canvas = canvas self.axes = axes self.horizOn = horizOn self.vertOn = vertOn xmin, xmax = axes[-1].get_xlim() ymin, ymax = axes[-1].get_ylim() xmid = 0.5 * (xmin + xmax) ymid = 0.5 * (ymin + ymax) self.visible = True self.useblit = useblit and self.canvas.supports_blit self.background = None self.needclear = False if self.useblit: lineprops['animated'] = True if vertOn: self.vlines = [ax.axvline(xmid, visible=False, **lineprops) for ax in axes] else: self.vlines = [] if horizOn: self.hlines = [ax.axhline(ymid, visible=False, **lineprops) for ax in axes] else: self.hlines = [] self.connect() def connect(self): """Connect events.""" self._cidmotion = self.canvas.mpl_connect('motion_notify_event', self.onmove) self._ciddraw = self.canvas.mpl_connect('draw_event', self.clear) def disconnect(self): """Disconnect events.""" self.canvas.mpl_disconnect(self._cidmotion) self.canvas.mpl_disconnect(self._ciddraw) def clear(self, event): """Clear the cursor.""" if self.ignore(event): return if self.useblit: self.background = ( self.canvas.copy_from_bbox(self.canvas.figure.bbox)) for line in self.vlines + self.hlines: line.set_visible(False) def onmove(self, event): if self.ignore(event): return if event.inaxes is None: return if not self.canvas.widgetlock.available(self): return self.needclear = True if not self.visible: return if self.vertOn: for line in self.vlines: line.set_xdata((event.xdata, event.xdata)) line.set_visible(self.visible) if self.horizOn: for line in self.hlines: line.set_ydata((event.ydata, event.ydata)) line.set_visible(self.visible) self._update() def _update(self): if self.useblit: if self.background is not None: self.canvas.restore_region(self.background) if self.vertOn: for ax, line in zip(self.axes, self.vlines): ax.draw_artist(line) if self.horizOn: for ax, line in zip(self.axes, self.hlines): ax.draw_artist(line) self.canvas.blit() else: self.canvas.draw_idle()
圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com
暂无评论...
更新日志
2024年11月01日
2024年11月01日
- 群星《戏梦》[320K/MP3][119.93MB]
- 群星《戏梦》[FLAC/分轨][308.4MB]
- 魔兽世界永久60级什么时间开 永久60级开启时间介绍
- 魔兽世界奥卡兹岛血藻刷新点一览 wlk奥卡兹岛血藻刷新位置介绍
- 英雄联盟s14中国队种子怎么排名 s14中国队种子队伍排名一览
- 柏菲·梁玉嵘《知音梁品》限量开盘母带ORMCD[低速原抓WAV+CUE]
- [东升唱片]孙露《寂寞诱惑AQCD》高码率[FLAC]
- 群星-第8届2012十大发烧唱片精选HQ2CD[WAV+CUE]
- 九号公司两轮电动安全季行动圆满收官:为行业树立安全管理新标杆
- 创新驱动未来 中国移动5G云游戏深化智能运维应用推动行业发展
- 大型手游“帧数拉满” 骁龙8至尊版游戏表现强悍
- 谢金燕.2002-YOYO姊妹【华特】【WAV+CUE】
- 群星.1994-摇滚列车【音乐家】【WAV+CUE】
- 陈艾湄.1996-牵绊【巨翼】【WAV+CUE】
- 群星《无法抗拒的谎言 电视剧原声带》[320K/MP3][69.98MB]