|
6 | 6 | import matplotlib as mpl |
7 | 7 |
|
8 | 8 | # Make a figure and axes with dimensions as desired. |
9 | | -fig = pyplot.figure(figsize=(8, 3)) |
| 9 | +fig = pyplot.figure(figsize=(8,3)) |
10 | 10 | ax1 = fig.add_axes([0.05, 0.80, 0.9, 0.15]) |
11 | 11 | ax2 = fig.add_axes([0.05, 0.475, 0.9, 0.15]) |
12 | 12 | ax3 = fig.add_axes([0.05, 0.15, 0.9, 0.15]) |
|
22 | 22 | # following gives a basic continuous colorbar with ticks |
23 | 23 | # and labels. |
24 | 24 | cb1 = mpl.colorbar.ColorbarBase(ax1, cmap=cmap, |
25 | | - norm=norm, |
26 | | - orientation='horizontal') |
| 25 | + norm=norm, |
| 26 | + orientation='horizontal') |
27 | 27 | cb1.set_label('Some Units') |
28 | 28 |
|
29 | 29 | # The second example illustrates the use of a ListedColormap, a |
|
39 | 39 | bounds = [1, 2, 4, 7, 8] |
40 | 40 | norm = mpl.colors.BoundaryNorm(bounds, cmap.N) |
41 | 41 | cb2 = mpl.colorbar.ColorbarBase(ax2, cmap=cmap, |
42 | | - norm=norm, |
43 | | - # to use 'extend', you must |
44 | | - # specify two extra boundaries: |
45 | | - boundaries=[0] + bounds + [13], |
46 | | - extend='both', |
47 | | - ticks=bounds, # optional |
48 | | - spacing='proportional', |
49 | | - orientation='horizontal') |
| 42 | + norm=norm, |
| 43 | + # to use 'extend', you must |
| 44 | + # specify two extra boundaries: |
| 45 | + boundaries=[0]+bounds+[13], |
| 46 | + extend='both', |
| 47 | + ticks=bounds, # optional |
| 48 | + spacing='proportional', |
| 49 | + orientation='horizontal') |
50 | 50 | cb2.set_label('Discrete intervals, some other units') |
51 | 51 |
|
52 | 52 | # The third example illustrates the use of custom length colorbar |
53 | 53 | # extensions, used on a colorbar with discrete intervals. |
54 | 54 | cmap = mpl.colors.ListedColormap([[0., .4, 1.], [0., .8, 1.], |
55 | | - [1., .8, 0.], [1., .4, 0.]]) |
| 55 | + [1., .8, 0.], [1., .4, 0.]]) |
56 | 56 | cmap.set_over((1., 0., 0.)) |
57 | 57 | cmap.set_under((0., 0., 1.)) |
58 | 58 |
|
59 | 59 | bounds = [-1., -.5, 0., .5, 1.] |
60 | 60 | norm = mpl.colors.BoundaryNorm(bounds, cmap.N) |
61 | 61 | cb3 = mpl.colorbar.ColorbarBase(ax3, cmap=cmap, |
62 | | - norm=norm, |
63 | | - boundaries=[-10] + bounds + [10], |
64 | | - extend='both', |
65 | | - # Make the length of each extension |
66 | | - # the same as the length of the |
67 | | - # interior colors: |
68 | | - extendfrac='auto', |
69 | | - ticks=bounds, |
70 | | - spacing='uniform', |
71 | | - orientation='horizontal') |
| 62 | + norm=norm, |
| 63 | + boundaries=[-10]+bounds+[10], |
| 64 | + extend='both', |
| 65 | + # Make the length of each extension |
| 66 | + # the same as the length of the |
| 67 | + # interior colors: |
| 68 | + extendfrac='auto', |
| 69 | + ticks=bounds, |
| 70 | + spacing='uniform', |
| 71 | + orientation='horizontal') |
72 | 72 | cb3.set_label('Custom extension lengths, some other units') |
73 | 73 |
|
74 | 74 | pyplot.show() |
0 commit comments