|
9 | 9 | See also the :doc:`contour image example
|
10 | 10 | </gallery/images_contours_and_fields/contour_image>`.
|
11 | 11 | """
|
| 12 | + |
12 | 13 | import matplotlib
|
13 | 14 | import numpy as np
|
14 | 15 | import matplotlib.cm as cm
|
|
24 | 25 | Z = (Z1 - Z2) * 2
|
25 | 26 |
|
26 | 27 | ###############################################################################
|
27 |
| -# Create a simple contour plot with labels using default colors. The |
28 |
| -# inline argument to clabel will control whether the labels are draw |
29 |
| -# over the line segments of the contour, removing the lines beneath |
30 |
| -# the label |
| 28 | +# Create a simple contour plot with labels using default colors. The inline |
| 29 | +# argument to clabel will control whether the labels are draw over the line |
| 30 | +# segments of the contour, removing the lines beneath the label. |
31 | 31 |
|
32 | 32 | fig, ax = plt.subplots()
|
33 | 33 | CS = ax.contour(X, Y, Z)
|
34 | 34 | ax.clabel(CS, inline=1, fontsize=10)
|
35 | 35 | ax.set_title('Simplest default with labels')
|
36 | 36 |
|
37 |
| - |
38 | 37 | ###############################################################################
|
39 |
| -# contour labels can be placed manually by providing list of positions |
40 |
| -# (in data coordinate). See ginput_manual_clabel.py for interactive |
41 |
| -# placement. |
| 38 | +# Contour labels can be placed manually by providing list of positions (in data |
| 39 | +# coordinate). See :doc:`/gallery/event_handling/ginput_manual_clabel_sgskip` |
| 40 | +# for interactive placement. |
42 | 41 |
|
43 | 42 | fig, ax = plt.subplots()
|
44 | 43 | CS = ax.contour(X, Y, Z)
|
45 |
| -manual_locations = [(-1, -1.4), (-0.62, -0.7), (-2, 0.5), (1.7, 1.2), (2.0, 1.4), (2.4, 1.7)] |
| 44 | +manual_locations = [ |
| 45 | + (-1, -1.4), (-0.62, -0.7), (-2, 0.5), (1.7, 1.2), (2.0, 1.4), (2.4, 1.7)] |
46 | 46 | ax.clabel(CS, inline=1, fontsize=10, manual=manual_locations)
|
47 | 47 | ax.set_title('labels at selected locations')
|
48 | 48 |
|
49 |
| - |
50 | 49 | ###############################################################################
|
51 | 50 | # You can force all the contours to be the same color.
|
52 | 51 |
|
|
64 | 63 | ax.clabel(CS, fontsize=9, inline=1)
|
65 | 64 | ax.set_title('Single color - negative contours solid')
|
66 | 65 |
|
67 |
| - |
68 | 66 | ###############################################################################
|
69 | 67 | # And you can manually specify the colors of the contour
|
70 | 68 |
|
|
76 | 74 | ax.clabel(CS, fontsize=9, inline=1)
|
77 | 75 | ax.set_title('Crazy lines')
|
78 | 76 |
|
79 |
| - |
80 | 77 | ###############################################################################
|
81 | 78 | # Or you can use a colormap to specify the colors; the default
|
82 | 79 | # colormap will be used for the contour lines
|
83 | 80 |
|
84 | 81 | fig, ax = plt.subplots()
|
85 | 82 | im = ax.imshow(Z, interpolation='bilinear', origin='lower',
|
86 |
| - cmap=cm.gray, extent=(-3, 3, -2, 2)) |
| 83 | + cmap=cm.gray, extent=(-3, 3, -2, 2)) |
87 | 84 | levels = np.arange(-1.2, 1.6, 0.2)
|
88 | 85 | CS = ax.contour(Z, levels, origin='lower', cmap='flag',
|
89 | 86 | linewidths=2, extent=(-3, 3, -2, 2))
|
|
0 commit comments