Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 723f33e

Browse files
committed
image_nonuniform: eliminate crowding
1 parent 0f3cc9d commit 723f33e

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
'''
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.
55
'''
66

7-
from matplotlib.pyplot import figure, show
87
import numpy as np
8+
import matplotlib.pyplot as plt
99
from matplotlib.image import NonUniformImage
1010
from matplotlib import cm
1111

1212
interp = 'nearest'
1313

14+
# Linear x array for cell centers:
1415
x = np.linspace(-4, 4, 9)
16+
17+
# Highly nonlinear x array:
1518
x2 = x**3
19+
1620
y = np.linspace(-4, 4, 9)
17-
#print('Size %d points' % (len(x) * len(y)))
21+
1822
z = np.sqrt(x[np.newaxis, :]**2 + y[:, np.newaxis]**2)
1923

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]
2328
im = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4),
2429
cmap=cm.Purples)
2530
im.set_data(x, y, z)
@@ -28,7 +33,7 @@
2833
ax.set_ylim(-4, 4)
2934
ax.set_title(interp)
3035

31-
ax = fig.add_subplot(222)
36+
ax = axs[0, 1]
3237
im = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, -4, 4),
3338
cmap=cm.Purples)
3439
im.set_data(x2, y, z)
@@ -39,7 +44,7 @@
3944

4045
interp = 'bilinear'
4146

42-
ax = fig.add_subplot(223)
47+
ax = axs[1, 0]
4348
im = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4),
4449
cmap=cm.Purples)
4550
im.set_data(x, y, z)
@@ -48,7 +53,7 @@
4853
ax.set_ylim(-4, 4)
4954
ax.set_title(interp)
5055

51-
ax = fig.add_subplot(224)
56+
ax = axs[1, 1]
5257
im = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, -4, 4),
5358
cmap=cm.Purples)
5459
im.set_data(x2, y, z)
@@ -57,4 +62,4 @@
5762
ax.set_ylim(-4, 4)
5863
ax.set_title(interp)
5964

60-
show()
65+
plt.show()

0 commit comments

Comments
 (0)