脚本专栏 
首页 > 脚本专栏 > 浏览文章

Python实现在matplotlib中两个坐标轴之间画一条直线光标的方法

(编辑:jimmy 日期: 2024/10/18 浏览:3 次 )

本文实例讲述了Python实现在matplotlib中两个坐标轴之间画一条直线光标的方法。分享给大家供大家参考。具体如下:

看看下面的例子和效果吧

# -*- coding: utf-8 -*-
from matplotlib.widgets import MultiCursor
from pylab import figure, show, np
t = np.arange(0.0, 2.0, 0.01)
s1 = np.sin(2*np.pi*t)
s2 = np.sin(4*np.pi*t)
fig = figure()
ax1 = fig.add_subplot(211)
ax1.plot(t, s1)
ax2 = fig.add_subplot(212, sharex=ax1)
ax2.plot(t, s2)
multi = MultiCursor(fig.canvas,(ax1,ax2),color='r',lw=1)
show()

下面是图形效果,看随着光标的移动,在两个图之间会画一条竖线

Python实现在matplotlib中两个坐标轴之间画一条直线光标的方法

这个功能有时还是比较有用的

希望本文所述对大家的Python程序设计有所帮助。

上一篇:在Python中操作列表之List.append()方法的使用
下一篇:简单介绍Python2.x版本中的cmp()方法的使用
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap