我真的对所有后端平台感到困惑,我应该在matplotlib中使用哪一个进行交互式绘图。
下面给出的是一个简单的代码,可以在Visual Studio Code上正常工作,当我单击无花果时,它会打印数据(如x,y坐标等)。而当我在Jupyter Notebook上运行相同的代码时,它运行时没有任何错误,但是当我单击绘图时却没有打印任何内容。
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
ax.plot(np.random.rand(10))
def onclick(event):
print('%s click: button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
('double' if event.dblclick else 'single', event.button,
event.x, event.y, event.xdata, event.ydata))
cid = fig.canvas.mpl_connect('button_press_event', onclick)