self.xs =list(line.get_xdata()) self.ys =list(line.get_ydata()) self.cid = line.figure.canvas.mpl_connect('button_press_event', self)def__call__(self, event):print('click', event)ifevent.inaxes!=self.line.axes:returnself.xs.append(event.xdata) self.ys.append(event.ydata) self...
这可以与get_contains()结合使用,以创建更灵活的交互效果: importmatplotlib.pyplotaspltimportnumpyasnp fig,ax=plt.subplots()x=np.linspace(0,10,100)line,=ax.plot(x,np.sin(x),picker=5)# 5 points tolerancedefon_pick(event):thisline=event.artist xdata,ydata=thisline.get_data()ind=event....
self.xs=list(line.get_xdata())self.ys=list(line.get_ydata())self.cid=line.figure.canvas.mpl_connect('button_press_event',self)def__call__(self,event):print('click',event)ifevent.inaxes!=self.line.axes:returnself.xs.append(event.xdata)self.ys.append(event.ydata)self.line.set_data(...
xdata = line.get_xdata() ydata = line.get_ydata() if position is None: position = xdata.mean() # find closest index start_ind = np.argmin(np.absolute(xdata - position)) if direction == 'right': end_ind = start_ind + 1 else: end_ind = start_ind - 1 line.axes.annotate(''...
get_xdata() ydata = thisline.get_ydata() ind = event.ind print('onpick1 line:', np.column_stack([xdata[ind], ydata[ind]])) elif isinstance(event.artist, Rectangle): patch = event.artist print('onpick1 patch:', patch.get_path()) elif isinstance(event.artist, Text): text = ...
get_xdata(self,orig=True)[source] 获取x轴数据 IforigisTrue, return the original data, else the processed data. get_xydata(self)[source] Return thexydata as a Nx2 numpy array. get_ydata(self,orig=True)[source] Return the ydata.IforigisTrue, return the original data, else the processe...
此时,通过指定索引值获取相应数据 boxplot['fliers'][1].get_xdata() Out[137]: array([2.]) boxplot['fliers'][1].get_ydata() Out[138]: array([1.79881989])发布于 2020-05-27 14:03 Matplotlib 数据可视化 可视化 赞同1添加评论 分享喜欢收藏申请转载 ...
运行程序后,当在画布上单击时,会在鼠标点击处,绘制出事件的 x、y、xdata、和 ydata 属性值: 接下来,我们编写另一个示例程序,此程序会在每次按下鼠标时绘制一条线段: frommatplotlibimportpyplotaspltclassLineBuilder:def__init__(self,line):self.line=lineself.xs=list(line.get_xdata())self.ys=list(lin...
= line self.xs = list(line.get_xdata()) self.ys = list(line.get_ydata()) ...
xdata:需要绘制的line中点的在x轴上的取值,若忽略,则默认为range(1,len(ydata)+1) ydata:需要绘制的line中点的在y轴上的取值 linewidth:线条的宽度 linestyle:线型 color:线条的颜色 markersize:标记的size 有三种方法可以用设置线的属性: 1)直接在plot()函数中设置 ...