绘制带彩色标记的散点图
import matplotlib.pyplot as plt import numpy as np x = np.random.rand(1000) # 不相关数据 y1 = np.random.rand(len(x)) # 强正相关数据 y2 = 1.2 + np.exp(x) ax1 = plt.subplot(121) # alpha:透明度 # marker:设置点状标记 plt.scatter(x, y1, color='indigo', alpha=0.3, edgecolors='white', label='no correl', marker='s') plt.xlabel('no correlation') plt.grid(True) plt.legend() # 共x、y轴刻度 ax2 = plt.subplot(122, sharey=ax1, sharex=ax1) plt.scatter(x, y2, color='green', alpha=0.3, edgecolors='grey', label='correl') plt.xlabel('strong correlation') plt.grid(True) plt.legend()
plt.show()