jupyter下利用matplotlib绘制散点图,可用于检验聚类效果。好记性不如烂笔头,记录在此以备用。
数据有3列:x坐标 y坐标 数值
直接上python代码:
import matplotlib.pyplot as plt
file = "D:\\data\\xy2.csv"
x = []
y = []
color = []
for line in open(file):
seg = line.strip().split()
if (len(seg) < 3):
continue
x1 = float(seg[0])
y1 = float(seg[1])
c1 = int(seg[2])
if (c1 > 10):
# 因为数值太多,只打印其中几个颜色
continue
x.append(x1)
y.append(y1)
color.append(c1/100)
plt.figure(figsize=(20, 20))
plt.scatter(x, y, c=color)
plt.show()
效果图: