栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

matplotlib二维矩阵散点图及每个点标记

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

matplotlib二维矩阵散点图及每个点标记

记录NLP作业中利用matplotlib绘制散点图并进行标记 原文:https://blog.csdn.net/wizardforcel/article/details/54782628

M_reduced是要求绘制的散点坐标
words 是单词
word2ind 字典,记录单词与坐标的对应关系

所使用的函数是annotate()

annotate(" 标记的文本 ", xy, xytext)

第一个参数是预标记的文本
第二个参数是预标注的点坐标
第三个参数是预标记文本的坐标

import numpy as np
import matplotlib.pyplot as plt

M_reduced= np.array([[1, 1], [-1, -1], [1, -1], [-1, 1], [0, 0]])
word2ind = {'test1': 0, 'test2': 1, 'test3': 2, 'test4': 3, 'test5': 4}
words = ['test1', 'test2', 'test3', 'test4', 'test5']

fig = plt.figure()
fig_sub1 = fig.add_subplot(111)

for i in range(len(words)):
	fig_sub1.scatter(M_reduced[word2ind[words[i]],0],M_reduced[word2ind[words[i]], 1],color='r',marker='x')
	plt.annotate(words[i], xy = (M_reduced[word2ind[words[i]], 0], M_reduced[word2ind[words[i]], 1]), xytext = (M_reduced[word2ind[words[i]], 0]+0.001, M_reduced[word2ind[words[i]], 1]+0.001)) 


plt.show()
运行结果

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/757006.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号