|
25 | 25 |
|
26 | 26 | ############################################################################### |
27 | 27 |
|
28 | | -plt.figure() |
| 28 | +fig, ax = plt.subplots() |
29 | 29 |
|
30 | 30 | # Filled contours using filled=True. |
31 | | -cs = ContourSet(plt.gca(), [0, 1, 2], [filled01, filled12], filled=True, cmap=cm.bone) |
32 | | -cbar = plt.colorbar(cs) |
| 31 | +cs = ContourSet(ax, [0, 1, 2], [filled01, filled12], filled=True, cmap=cm.bone) |
| 32 | +cbar = fig.colorbar(cs) |
33 | 33 |
|
34 | 34 | # Contour lines (non-filled). |
35 | | -lines = ContourSet(plt.gca(), [0, 1, 2], [lines0, lines1, lines2], cmap=cm.cool, |
36 | | - linewidths=3) |
| 35 | +lines = ContourSet( |
| 36 | + ax, [0, 1, 2], [lines0, lines1, lines2], cmap=cm.cool, linewidths=3) |
37 | 37 | cbar.add_lines(lines) |
38 | 38 |
|
39 | | -plt.axis([-0.5, 3.5, -0.5, 4.5]) |
40 | | -plt.title('User-specified contours') |
| 39 | +ax.set(xlim=(-0.5, 3.5), ylim=(-0.5, 4.5), |
| 40 | + title='User-specified contours') |
41 | 41 |
|
42 | 42 | ############################################################################### |
43 | 43 | # Multiple filled contour lines can be specified in a single list of polygon |
44 | 44 | # vertices along with a list of vertex kinds (code types) as described in the |
45 | 45 | # Path class. This is particularly useful for polygons with holes. |
46 | 46 | # Here a code type of 1 is a MOVETO, and 2 is a LINETO. |
47 | 47 |
|
48 | | -plt.figure() |
| 48 | +fig, ax = plt.subplots() |
49 | 49 | filled01 = [[[0, 0], [3, 0], [3, 3], [0, 3], [1, 1], [1, 2], [2, 2], [2, 1]]] |
50 | 50 | kinds01 = [[1, 2, 2, 2, 1, 2, 2, 2]] |
51 | | -cs = ContourSet(plt.gca(), [0, 1], [filled01], [kinds01], filled=True) |
52 | | -cbar = plt.colorbar(cs) |
| 51 | +cs = ContourSet(ax, [0, 1], [filled01], [kinds01], filled=True) |
| 52 | +cbar = fig.colorbar(cs) |
53 | 53 |
|
54 | | -plt.axis([-0.5, 3.5, -0.5, 3.5]) |
55 | | -plt.title('User specified filled contours with holes') |
| 54 | +ax.set(xlim=(-0.5, 3.5), ylim=(-0.5, 3.5), |
| 55 | + title='User specified filled contours with holes') |
56 | 56 |
|
57 | 57 | plt.show() |
0 commit comments