散点图
import numpy as np
import matplotlib.pyplot as plt
x = np.random.randn(100)
y = np.random.randn(100)
plt.scatter(x, y)
plt.show()
2、在一幅图中绘制两组数据。
import numpy as np
import matplotlib.pyplot as plt
x1 = np.random.randn(1000)
y1 = np.random.randn(1000)
x2 = np.random.randn(1000)
y2 = np.random.randn(1000)
plt.scatter(x1, y1, edgecolors='b', s=10)
plt.scatter(x2, y2, edgecolors='r', s=10)
plt.show()
其完整代码为:
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']#显示中文
x1 = np.abs(np.random.randn(100)*100)
y1 = np.abs(np.random.randn(100)*100)
x2 = np.abs(np.random.randn(100)*100)
y2 = np.abs(np.random.randn(100)*100)
x3 = np.abs(np.random.randn(100)*100)
y3 = np.abs(np.random.randn(100)*100)
plt.scatter(x1, y1, edgecolors='b', s=10, marker='1')
plt.scatter(x2, y2, edgecolors='r', s=10, marker='o')
plt.scatter(x3, y3, edgecolors='g', s=10, marker='s')
plt.title("散点图")
plt.legend(["第一组", "第二组", "第三组"])
plt.xlabel("x轴")plt.ylabel("y轴")
plt.show()