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

Skip to content

Commit 47c7364

Browse files
authored
Merge pull request #6609 from efiring/example_tweaks
Example tweaks
2 parents 68d10b3 + 7f8b927 commit 47c7364

File tree

6 files changed

+46
-45
lines changed

6 files changed

+46
-45
lines changed

examples/api/collections_demo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
for c in plt.rcParams['axes.prop_cycle'].by_key()['color']]
4343

4444
fig, axes = plt.subplots(2, 2)
45+
fig.subplots_adjust(top=0.92, left=0.07, right=0.97,
46+
hspace=0.3, wspace=0.3)
4547
((ax1, ax2), (ax3, ax4)) = axes # unpack the axes
4648

4749

examples/pylab_examples/break.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/pylab_examples/hexbin_demo.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@
1717
ymin = y.min()
1818
ymax = y.max()
1919

20-
plt.subplots_adjust(hspace=0.5)
21-
plt.subplot(121)
22-
plt.hexbin(x, y, cmap=plt.cm.YlOrRd_r)
23-
plt.axis([xmin, xmax, ymin, ymax])
24-
plt.title("Hexagon binning")
25-
cb = plt.colorbar()
20+
fig, axs = plt.subplots(ncols=2, sharey=True, figsize=(7, 4))
21+
fig.subplots_adjust(hspace=0.5, left=0.07, right=0.93)
22+
ax = axs[0]
23+
hb = ax.hexbin(x, y, gridsize=50, cmap='inferno')
24+
ax.axis([xmin, xmax, ymin, ymax])
25+
ax.set_title("Hexagon binning")
26+
cb = fig.colorbar(hb, ax=ax)
2627
cb.set_label('counts')
2728

28-
plt.subplot(122)
29-
plt.hexbin(x, y, bins='log', cmap=plt.cm.YlOrRd_r)
30-
plt.axis([xmin, xmax, ymin, ymax])
31-
plt.title("With a log color scale")
32-
cb = plt.colorbar()
29+
ax = axs[1]
30+
hb = ax.hexbin(x, y, gridsize=50, bins='log', cmap='inferno')
31+
ax.axis([xmin, xmax, ymin, ymax])
32+
ax.set_title("With a log color scale")
33+
cb = fig.colorbar(hb, ax=ax)
3334
cb.set_label('log10(N)')
3435

3536
plt.show()
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()

examples/pylab_examples/image_origin.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,14 @@
77
import matplotlib.pyplot as plt
88
import numpy as np
99

10-
x = np.arange(100.0)
11-
x.shape = (10, 10)
10+
x = np.arange(120)
11+
x.shape = (10, 12)
1212

1313
interp = 'bilinear'
14-
#interp = 'nearest'
15-
lim = -2, 11, -2, 6
16-
plt.subplot(211, facecolor='g')
17-
plt.title('blue should be up')
18-
plt.imshow(x, origin='upper', interpolation=interp)
19-
#plt.axis(lim)
14+
fig, axs = plt.subplots(nrows=2, sharex=True, figsize=(3, 5))
15+
axs[0].set_title('blue should be up')
16+
axs[0].imshow(x, origin='upper', interpolation=interp)
2017

21-
plt.subplot(212, facecolor='y')
22-
plt.title('blue should be down')
23-
plt.imshow(x, origin='lower', interpolation=interp)
24-
#plt.axis(lim)
18+
axs[1].set_title('blue should be down')
19+
axs[1].imshow(x, origin='lower', interpolation=interp)
2520
plt.show()

examples/scales/scales.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
"""
44
import numpy as np
55
import matplotlib.pyplot as plt
6+
from matplotlib.ticker import NullFormatter
67

8+
np.random.seed(1)
79
# make up some data in the interval ]0, 1[
810
y = np.random.normal(loc=0.5, scale=0.4, size=1000)
911
y = y[(y > 0) & (y < 1)]
1012
y.sort()
1113
x = np.arange(len(y))
1214

1315
# plot with various axes scales
14-
fig, axs = plt.subplots(2, 2)
16+
fig, axs = plt.subplots(2, 2, sharex=True)
17+
fig.subplots_adjust(left=0.08, right=0.98, wspace=0.3)
1518

1619
# linear
1720
ax = axs[0, 0]
@@ -30,18 +33,19 @@
3033

3134

3235
# symmetric log
33-
ax = axs[1, 0]
36+
ax = axs[1, 1]
3437
ax.plot(x, y - y.mean())
35-
ax.set_yscale('symlog', linthreshy=0.05)
38+
ax.set_yscale('symlog', linthreshy=0.02)
3639
ax.set_title('symlog')
3740
ax.grid(True)
3841

3942
# logit
40-
ax = axs[1, 1]
43+
ax = axs[1, 0]
4144
ax.plot(x, y)
4245
ax.set_yscale('logit')
4346
ax.set_title('logit')
4447
ax.grid(True)
48+
ax.yaxis.set_minor_formatter(NullFormatter())
4549

4650

4751
plt.show()

0 commit comments

Comments
 (0)