matplotlib.pyplot.scatter(x, y, s, c, marker, cmap, norm,
vim, vmax, alpha, linewidths, verts, hold, **kwargs)
形如shape(n, )的数组,x是散点图的x轴数据,y是y轴数据
色彩,或者颜色序列
plt.scatter([1, 2, 3], [5, 6, 7], c='red')
plt.show()
plt.scatter([1, 2, 3], [5, 6, 7], c=[10, 20, 30])
plt.show()
plt.scatter([1, 2, 3], [5, 6, 7], c=[10, 20, 30], marker='v')
plt.show()
plt.scatter(2, 4)
plt.show()
random.seed(1)
x = np.random.rand(10)
y = np.random.rand(10)
plt.scatter(x, y, c='green', marker='o')
plt.show()
list(np.array(数组).T[])
来截取二维列表的第0未数据import random
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# 创建数据集
def createDataSet():
return [[1, 1], [1, 2], [2, 1], [6, 4], [6, 3], [5, 4]]
if __name__ == '__main__':
dataset = createDataSet() # dataset 是list类型数据
print(np.array(dataset).T[0]) # [1 1 2 6 6 5]
print(list(np.array(dataset).T[0])) # [1, 1, 2, 6, 6, 5] 这个是合法的x轴数据
x = list(np.array(dataset).T[0])
y = list(np.array(dataset).T[1])
plt.scatter(x, y, c='pink', marker=',')
plt.show()