|
1 | 1 | ''' |
2 | | -This illustrates the NonUniformImage class, which still needs |
3 | | -an axes method interface; either a separate interface, or a |
4 | | -generalization of imshow. |
| 2 | +This illustrates the NonUniformImage class. It is not |
| 3 | +available via an Axes method but it is easily added to an |
| 4 | +Axes instance as shown here. |
5 | 5 | ''' |
6 | 6 |
|
7 | | -from matplotlib.pyplot import figure, show |
8 | 7 | import numpy as np |
| 8 | +import matplotlib.pyplot as plt |
9 | 9 | from matplotlib.image import NonUniformImage |
10 | 10 | from matplotlib import cm |
11 | 11 |
|
12 | 12 | interp = 'nearest' |
13 | 13 |
|
| 14 | +# Linear x array for cell centers: |
14 | 15 | x = np.linspace(-4, 4, 9) |
| 16 | + |
| 17 | +# Highly nonlinear x array: |
15 | 18 | x2 = x**3 |
| 19 | + |
16 | 20 | y = np.linspace(-4, 4, 9) |
17 | | -#print('Size %d points' % (len(x) * len(y))) |
| 21 | + |
18 | 22 | z = np.sqrt(x[np.newaxis, :]**2 + y[:, np.newaxis]**2) |
19 | 23 |
|
20 | | -fig = figure() |
21 | | -fig.suptitle('NonUniformImage class') |
22 | | -ax = fig.add_subplot(221) |
| 24 | +fig, axs = plt.subplots(nrows=2, ncols=2) |
| 25 | +fig.subplots_adjust(bottom=0.07, hspace=0.3) |
| 26 | +fig.suptitle('NonUniformImage class', fontsize='large') |
| 27 | +ax = axs[0, 0] |
23 | 28 | im = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4), |
24 | 29 | cmap=cm.Purples) |
25 | 30 | im.set_data(x, y, z) |
|
28 | 33 | ax.set_ylim(-4, 4) |
29 | 34 | ax.set_title(interp) |
30 | 35 |
|
31 | | -ax = fig.add_subplot(222) |
| 36 | +ax = axs[0, 1] |
32 | 37 | im = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, -4, 4), |
33 | 38 | cmap=cm.Purples) |
34 | 39 | im.set_data(x2, y, z) |
|
39 | 44 |
|
40 | 45 | interp = 'bilinear' |
41 | 46 |
|
42 | | -ax = fig.add_subplot(223) |
| 47 | +ax = axs[1, 0] |
43 | 48 | im = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4), |
44 | 49 | cmap=cm.Purples) |
45 | 50 | im.set_data(x, y, z) |
|
48 | 53 | ax.set_ylim(-4, 4) |
49 | 54 | ax.set_title(interp) |
50 | 55 |
|
51 | | -ax = fig.add_subplot(224) |
| 56 | +ax = axs[1, 1] |
52 | 57 | im = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, -4, 4), |
53 | 58 | cmap=cm.Purples) |
54 | 59 | im.set_data(x2, y, z) |
|
57 | 62 | ax.set_ylim(-4, 4) |
58 | 63 | ax.set_title(interp) |
59 | 64 |
|
60 | | -show() |
| 65 | +plt.show() |
0 commit comments