问题遇到的现象和发生背景
我想在绘制多个子图时,显示随鼠标移动的竖线,这会帮助我在看数据时定位其他数据的位置,我利用MultiCursor显示这条竖线,但是我将MultiCursor写在了函数的内部,并调用函数绘图时,并不显示竖线,请问各位又没解决办法?
问题相关代码,请勿粘贴截图
import pandas as pd
import matpoltlib.pyplot as plt
from pylab import mpl
from matplotlib.widgets import MultiCursor
pic = ['A','B','C','D']
data = pd.read_csv(r'C:\Users\SUN\test.csv')
def polt_pictures(data,pic):
len_pic = len(pic)
b = len_pic*4
ax = []
fig = plt.figure(figsize=(12,b))
for n in np.arange(0,len_pic):
axx = 'ax'+pic[n]
axx = fig.add_subpolt(len_pic,1,n+1)
ax.append(axx)
axx.set_ylabel(pic[n])
axx.polt(data[pic[n]],color='grey')
ax = tuple(ax)
multi = MultiCursor(fig.canvas,ax,color='red')
plt.show()
polt_picture(data,pic)
运行结果及报错内容
当不使用函数直接使用时,能够显示随鼠标移动的竖线,但是封装为函数后调用,则不显示