python – matplotlib散点图中的标记点
发布时间:2020-12-20 12:01:38 所属栏目:Python 来源:网络整理
导读:参见英文答案 Display numbers instead of points using pyplot ????????????????????????????????????1个 ???????????? matplotlib scatter plot with different text at each data point????????????????????????????????????4个 编辑:这个问题不重复,我
参见英文答案 >
Display numbers instead of points using pyplot ????????????????????????????????????1个
>???????????? matplotlib scatter plot with different text at each data point????????????????????????????????????4个 编辑:这个问题不重复,我不想绘制数字而不是点数,我想在我的点旁边绘制数字. 我正在使用matplotlib创建一个情节.绘制[[3,9],[4,8],[5,4]]有三点 我可以轻松地用它们制作散点图 import matplotlib.pyplot as plt allPoints = [[3,4]] f,diagram = plt.subplots(1) for i in range(3): xPoint = allPoints[i][0] yPoint = allPoints[i][1] diagram.plot(xPoint,yPoint,'bo') 这产生了这个情节: 我想用数字1,2,3标记每个点. 基于this SO回答我试图使用注释来标记每个点. import matplotlib.pyplot as plt allPoints = [[1,3,[2,4,[3,5,diagram = plt.subplots(1) for i in range(3): pointRefNumber = allPoints[i][0] xPoint = allPoints[i][1] yPoint = allPoints[i][2] diagram.annotate(pointRefNumber,(xPoint,yPoint)) 这会产生一个空白图.我正在密切关注另一个答案,但它没有产生任何情节.我哪里弄错了? 解决方法
你可以这样做:
import matplotlib.pyplot as plt points = [[3,4]] for i in range(len(points)): x = points[i][0] y = points[i][1] plt.plot(x,y,'bo') plt.text(x * (1 + 0.01),y * (1 + 0.01),i,fontsize=12) plt.xlim((0,10)) plt.ylim((0,10)) plt.show() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |