散点图遮盖

屏蔽一些数据点,并添加一条线去标记掩码区域。

散点图遮盖示例

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. # Fixing random state for reproducibility
  4. np.random.seed(19680801)
  5. N = 100
  6. r0 = 0.6
  7. x = 0.9 * np.random.rand(N)
  8. y = 0.9 * np.random.rand(N)
  9. area = (20 * np.random.rand(N))**2 # 0 to 10 point radii
  10. c = np.sqrt(area)
  11. r = np.sqrt(x * x + y * y)
  12. area1 = np.ma.masked_where(r < r0, area)
  13. area2 = np.ma.masked_where(r >= r0, area)
  14. plt.scatter(x, y, s=area1, marker='^', c=c)
  15. plt.scatter(x, y, s=area2, marker='o', c=c)
  16. # Show the boundary between the regions:
  17. theta = np.arange(0, np.pi / 2, 0.01)
  18. plt.plot(r0 * np.cos(theta), r0 * np.sin(theta))
  19. plt.show()

下载这个示例