python标记点_Matplotlib:如何单独标记点?

所有这些都可以在函数或类中隐藏起来:# import stuff

import matplotlib.pyplot as plt

import numpy as np

# create dictionary we will close over (twice)

label_dict = dict()

# helper function to do the scatter plot + shove data into label_dict

def lab_scatter(ax, x, y, label_list, *args, **kwargs):

if 'picker' not in kwargs:

kwargs['picker'] = 3

sc = ax.scatter(x, y, *args, **kwargs)

label_dict[sc] = label_list

return sc

# call back function which also closes over label_dict, should add more sanity checks

# (that artist is actually in the dict, deal with multiple hits in ind ect)

def cb_fun(event):

# grab list of labels from the dict, print the right one

print label_dict[event.artist][event.ind[0]]

# create the figure and axes to use

fig, ax = plt.subplots(1, 1)

# loop over 5 synthetic data sets

for j in range(5):

# use our helper function to do the plotting

lab_scatter(ax,

np.ones(10) * j,

np.random.rand(10),

# give each point a unique label

label_list = ['label_{s}_{f}'.format(s=j, f=k) for k in range(10)])

# connect up the call back function

cid = fig.canvas.mpl_connect('pick_event', cb_fun)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值