我找到了以下使用鼠标选择数据的示例,但是当我将 onpick 函数与极坐标图一起使用时,出现以下错误:
xdata = thisline.get_xdata()
AttributeError: 'PolarAxesSubplot' object has no attribute 'get_xdata'
使用鼠标获取 theta 和 r 的极坐标方法是什么?
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title('click on points')
line, = ax.plot(np.random.rand(100), 'o', picker=5) # 5 points tolerance
def onpick(event):
thisline = event.artist
xdata = thisline.get_xdata()
ydata = thisline.get_ydata()
ind = event.ind
print 'onpick points:', zip(xdata[ind], ydata[ind])
fig.canvas.mpl_connect('pick_event', onpick)
plt.show()