Contour手册

使用ContourSet显示自己的轮廓线和多边形的示例。

  1. import matplotlib.pyplot as plt
  2. from matplotlib.contour import ContourSet
  3. import matplotlib.cm as cm

每个级别的轮廓线是多边形的列表/元组。

  1. lines0 = [[[0, 0], [0, 4]]]
  2. lines1 = [[[2, 0], [1, 2], [1, 3]]]
  3. lines2 = [[[3, 0], [3, 2]], [[3, 3], [3, 4]]] # Note two lines.

两个级别之间的填充等高线也是多边形的列表/元组。点可以顺时针或逆时针排列。

  1. filled01 = [[[0, 0], [0, 4], [1, 3], [1, 2], [2, 0]]]
  2. filled12 = [[[2, 0], [3, 0], [3, 2], [1, 3], [1, 2]], # Note two polygons.
  3. [[1, 4], [3, 4], [3, 3]]]
  1. plt.figure()
  2. # Filled contours using filled=True.
  3. cs = ContourSet(plt.gca(), [0, 1, 2], [filled01, filled12], filled=True, cmap=cm.bone)
  4. cbar = plt.colorbar(cs)
  5. # Contour lines (non-filled).
  6. lines = ContourSet(plt.gca(), [0, 1, 2], [lines0, lines1, lines2], cmap=cm.cool,
  7. linewidths=3)
  8. cbar.add_lines(lines)
  9. plt.axis([-0.5, 3.5, -0.5, 4.5])
  10. plt.title('User-specified contours')

Contour手册示例

可以在单个多边形顶点列表中指定多个填充轮廓线以及Path类中描述的顶点种类(代码类型)列表。 这对于带孔的多边形特别有用。 代码类型1是MOVETO,2是LINETO。

  1. plt.figure()
  2. filled01 = [[[0, 0], [3, 0], [3, 3], [0, 3], [1, 1], [1, 2], [2, 2], [2, 1]]]
  3. kinds01 = [[1, 2, 2, 2, 1, 2, 2, 2]]
  4. cs = ContourSet(plt.gca(), [0, 1], [filled01], [kinds01], filled=True)
  5. cbar = plt.colorbar(cs)
  6. plt.axis([-0.5, 3.5, -0.5, 3.5])
  7. plt.title('User specified filled contours with holes')
  8. plt.show()

Contour手册示例2

下载这个示例