Skip to content

Commit d0d9632

Browse files
committed
pep8ify: examples/axes_grid
Signed-off-by: Thomas Hisch <t.hisch@gmail.com>
1 parent 1c37e78 commit d0d9632

22 files changed

+214
-229
lines changed

examples/axes_grid/demo_axes_divider.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import matplotlib.pyplot as plt
22

3+
34
def get_demo_image():
45
import numpy as np
56
from matplotlib.cbook import get_sample_data
67
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
78
z = np.load(f)
89
# z is a numpy array of 15x15
9-
return z, (-3,4,-4,3)
10+
return z, (-3, 4, -4, 3)
1011

1112

1213
def demo_simple_image(ax):
@@ -20,7 +21,7 @@ def demo_simple_image(ax):
2021
def demo_locatable_axes_hard(fig1):
2122

2223
from mpl_toolkits.axes_grid1 \
23-
import SubplotDivider, LocatableAxes, Size
24+
import SubplotDivider, LocatableAxes, Size
2425

2526
divider = SubplotDivider(fig1, 2, 2, 2, aspect=True)
2627

@@ -30,9 +31,9 @@ def demo_locatable_axes_hard(fig1):
3031
# axes for colorbar
3132
ax_cb = LocatableAxes(fig1, divider.get_position())
3233

33-
h = [Size.AxesX(ax), # main axes
34-
Size.Fixed(0.05), # padding, 0.1 inch
35-
Size.Fixed(0.2), # colorbar, 0.3 inch
34+
h = [Size.AxesX(ax), # main axes
35+
Size.Fixed(0.05), # padding, 0.1 inch
36+
Size.Fixed(0.2), # colorbar, 0.3 inch
3637
]
3738

3839
v = [Size.AxesY(ax)]

examples/axes_grid/demo_axes_grid.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import matplotlib.pyplot as plt
22
from mpl_toolkits.axes_grid1 import AxesGrid
33

4+
45
def get_demo_image():
56
import numpy as np
67
from matplotlib.cbook import get_sample_data
78
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
89
z = np.load(f)
910
# z is a numpy array of 15x15
10-
return z, (-3,4,-4,3)
11+
return z, (-3, 4, -4, 3)
12+
1113

1214
def demo_simple_grid(fig):
1315
"""
1416
A grid of 2x2 images with 0.05 inch pad between images and only
1517
the lower-left axes is labeled.
1618
"""
17-
grid = AxesGrid(fig, 141, # similar to subplot(141)
18-
nrows_ncols = (2, 2),
19+
grid = AxesGrid(fig, 141, # similar to subplot(141)
20+
nrows_ncols=(2, 2),
1921
axes_pad = 0.05,
2022
label_mode = "1",
2123
)
@@ -24,7 +26,8 @@ def demo_simple_grid(fig):
2426
for i in range(4):
2527
im = grid[i].imshow(Z, extent=extent, interpolation="nearest")
2628

27-
# This only affects axes in first column and second row as share_all = False.
29+
# This only affects axes in first column and second row as share_all =
30+
# False.
2831
grid.axes_llc.set_xticks([-2, 0, 2])
2932
grid.axes_llc.set_yticks([-2, 0, 2])
3033

@@ -33,8 +36,8 @@ def demo_grid_with_single_cbar(fig):
3336
"""
3437
A grid of 2x2 images with a single colorbar
3538
"""
36-
grid = AxesGrid(fig, 142, # similar to subplot(142)
37-
nrows_ncols = (2, 2),
39+
grid = AxesGrid(fig, 142, # similar to subplot(142)
40+
nrows_ncols=(2, 2),
3841
axes_pad = 0.0,
3942
share_all=True,
4043
label_mode = "L",
@@ -50,7 +53,7 @@ def demo_grid_with_single_cbar(fig):
5053

5154
for cax in grid.cbar_axes:
5255
cax.toggle_label(False)
53-
56+
5457
# This affects all axes as share_all = True.
5558
grid.axes_llc.set_xticks([-2, 0, 2])
5659
grid.axes_llc.set_yticks([-2, 0, 2])
@@ -61,8 +64,8 @@ def demo_grid_with_each_cbar(fig):
6164
A grid of 2x2 images. Each image has its own colorbar.
6265
"""
6366

64-
grid = AxesGrid(F, 143, # similar to subplot(143)
65-
nrows_ncols = (2, 2),
67+
grid = AxesGrid(F, 143, # similar to subplot(143)
68+
nrows_ncols=(2, 2),
6669
axes_pad = 0.1,
6770
label_mode = "1",
6871
share_all = True,
@@ -83,14 +86,15 @@ def demo_grid_with_each_cbar(fig):
8386
grid.axes_llc.set_xticks([-2, 0, 2])
8487
grid.axes_llc.set_yticks([-2, 0, 2])
8588

89+
8690
def demo_grid_with_each_cbar_labelled(fig):
8791
"""
8892
A grid of 2x2 images. Each image has its own colorbar.
8993
"""
9094

91-
grid = AxesGrid(F, 144, # similar to subplot(144)
92-
nrows_ncols = (2, 2),
93-
axes_pad = ( 0.45, 0.15),
95+
grid = AxesGrid(F, 144, # similar to subplot(144)
96+
nrows_ncols=(2, 2),
97+
axes_pad = (0.45, 0.15),
9498
label_mode = "1",
9599
share_all = True,
96100
cbar_location="right",
@@ -100,15 +104,15 @@ def demo_grid_with_each_cbar_labelled(fig):
100104
)
101105
Z, extent = get_demo_image()
102106

103-
# Use a different colorbar range every time
107+
# Use a different colorbar range every time
104108
limits = ((0, 1), (-2, 2), (-1.7, 1.4), (-1.5, 1))
105109
for i in range(4):
106-
im = grid[i].imshow(Z, extent=extent, interpolation="nearest",
107-
vmin = limits[i][0], vmax = limits[i][1])
110+
im = grid[i].imshow(Z, extent=extent, interpolation="nearest",
111+
vmin=limits[i][0], vmax=limits[i][1])
108112
grid.cbar_axes[i].colorbar(im)
109113

110114
for i, cax in enumerate(grid.cbar_axes):
111-
cax.set_yticks((limits[i][0], limits[i][1]))
115+
cax.set_yticks((limits[i][0], limits[i][1]))
112116

113117
# This affects all axes because we set share_all = True.
114118
grid.axes_llc.set_xticks([-2, 0, 2])
@@ -127,4 +131,3 @@ def demo_grid_with_each_cbar_labelled(fig):
127131

128132
plt.draw()
129133
plt.show()
130-

examples/axes_grid/demo_axes_grid2.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
from mpl_toolkits.axes_grid1 import ImageGrid
33
import numpy as np
44

5+
56
def get_demo_image():
67
from matplotlib.cbook import get_sample_data
78
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
89
z = np.load(f)
910
# z is a numpy array of 15x15
10-
return z, (-3,4,-4,3)
11+
return z, (-3, 4, -4, 3)
1112

1213

1314
def add_inner_title(ax, title, loc, size=None, **kwargs):
@@ -28,27 +29,27 @@ def add_inner_title(ax, title, loc, size=None, **kwargs):
2829

2930
# prepare images
3031
Z, extent = get_demo_image()
31-
ZS = [Z[i::3,:] for i in range(3)]
32+
ZS = [Z[i::3, :] for i in range(3)]
3233
extent = extent[0], extent[1]/3., extent[2], extent[3]
3334

3435
# demo 1 : colorbar at each axes
3536

36-
grid = ImageGrid(F, 211, # similar to subplot(111)
37-
nrows_ncols = (1, 3),
38-
direction="row",
39-
axes_pad = 0.05,
40-
add_all=True,
41-
label_mode = "1",
42-
share_all = True,
43-
cbar_location="top",
44-
cbar_mode="each",
45-
cbar_size="7%",
46-
cbar_pad="1%",
47-
)
48-
37+
grid = ImageGrid(F, 211, # similar to subplot(111)
38+
nrows_ncols=(1, 3),
39+
direction="row",
40+
axes_pad = 0.05,
41+
add_all=True,
42+
label_mode = "1",
43+
share_all = True,
44+
cbar_location="top",
45+
cbar_mode="each",
46+
cbar_size="7%",
47+
cbar_pad="1%",
48+
)
4949

5050
for ax, z in zip(grid, ZS):
51-
im = ax.imshow(z, origin="lower", extent=extent, interpolation="nearest")
51+
im = ax.imshow(
52+
z, origin="lower", extent=extent, interpolation="nearest")
5253
ax.cax.colorbar(im)
5354

5455
for ax, im_title in zip(grid, ["Image 1", "Image 2", "Image 3"]):
@@ -59,8 +60,8 @@ def add_inner_title(ax, title, loc, size=None, **kwargs):
5960
ax.cax.toggle_label(True)
6061
#axis = ax.cax.axis[ax.cax.orientation]
6162
#axis.label.set_text("counts s$^{-1}$")
62-
#axis.label.set_size(10)
63-
#axis.major_ticklabels.set_size(6)
63+
# axis.label.set_size(10)
64+
# axis.major_ticklabels.set_size(6)
6465

6566
# changing the colorbar ticks
6667
grid[1].cax.set_xticks([-1, 0, 1])
@@ -69,11 +70,10 @@ def add_inner_title(ax, title, loc, size=None, **kwargs):
6970
grid[0].set_xticks([-2, 0])
7071
grid[0].set_yticks([-2, 0, 2])
7172

72-
7373
# demo 2 : shared colorbar
7474

7575
grid2 = ImageGrid(F, 212,
76-
nrows_ncols = (1, 3),
76+
nrows_ncols=(1, 3),
7777
direction="row",
7878
axes_pad = 0.05,
7979
add_all=True,

examples/axes_grid/demo_axes_hbox_divider.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from mpl_toolkits.axes_grid1.axes_divider import HBoxDivider
44
import mpl_toolkits.axes_grid1.axes_size as Size
55

6+
67
def make_heights_equal(fig, rect, ax1, ax2, pad):
78
# pad in inches
8-
9+
910
h1, v1 = Size.AxesX(ax1), Size.AxesY(ax1)
1011
h2, v2 = Size.AxesX(ax2), Size.AxesY(ax2)
1112

@@ -16,23 +17,22 @@ def make_heights_equal(fig, rect, ax1, ax2, pad):
1617
horizontal=[h1, pad_h, h2],
1718
vertical=[v1, pad_v, v2])
1819

19-
2020
ax1.set_axes_locator(my_divider.new_locator(0))
2121
ax2.set_axes_locator(my_divider.new_locator(2))
2222

23-
23+
2424
if __name__ == "__main__":
2525

26-
arr1 = np.arange(20).reshape((4,5))
27-
arr2 = np.arange(20).reshape((5,4))
26+
arr1 = np.arange(20).reshape((4, 5))
27+
arr2 = np.arange(20).reshape((5, 4))
2828

29-
fig, (ax1, ax2) = plt.subplots(1,2)
29+
fig, (ax1, ax2) = plt.subplots(1, 2)
3030
ax1.imshow(arr1, interpolation="nearest")
3131
ax2.imshow(arr2, interpolation="nearest")
3232

33-
rect = 111 # subplot param for combined axes
34-
make_heights_equal(fig, rect, ax1, ax2, pad=0.5) # pad in inches
35-
33+
rect = 111 # subplot param for combined axes
34+
make_heights_equal(fig, rect, ax1, ax2, pad=0.5) # pad in inches
35+
3636
for ax in [ax1, ax2]:
3737
ax.locator_params(nbins=4)
3838

@@ -47,4 +47,3 @@ def make_heights_equal(fig, rect, ax1, ax2, pad):
4747
bbox=dict(boxstyle="round, pad=1", fc="w"))
4848

4949
plt.show()
50-

examples/axes_grid/demo_axes_rgb.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,48 @@
33

44
from mpl_toolkits.axes_grid1.axes_rgb import make_rgb_axes, RGBAxes
55

6+
67
def get_demo_image():
78
from matplotlib.cbook import get_sample_data
89
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
910
z = np.load(f)
1011
# z is a numpy array of 15x15
11-
return z, (-3,4,-4,3)
12-
12+
return z, (-3, 4, -4, 3)
1313

1414

1515
def get_rgb():
1616
Z, extent = get_demo_image()
1717

18-
Z[Z<0] = 0.
18+
Z[Z < 0] = 0.
1919
Z = Z/Z.max()
2020

21-
R = Z[:13,:13]
22-
G = Z[2:,2:]
23-
B = Z[:13,2:]
21+
R = Z[:13, :13]
22+
G = Z[2:, 2:]
23+
B = Z[:13, 2:]
2424

2525
return R, G, B
2626

2727

2828
def make_cube(r, g, b):
2929
ny, nx = r.shape
3030
R = np.zeros([ny, nx, 3], dtype="d")
31-
R[:,:,0] = r
31+
R[:, :, 0] = r
3232
G = np.zeros_like(R)
33-
G[:,:,1] = g
33+
G[:, :, 1] = g
3434
B = np.zeros_like(R)
35-
B[:,:,2] = b
35+
B[:, :, 2] = b
3636

3737
RGB = R + G + B
3838

3939
return R, G, B, RGB
4040

4141

42-
4342
def demo_rgb():
4443
fig, ax = plt.subplots()
4544
ax_r, ax_g, ax_b = make_rgb_axes(ax, pad=0.02)
46-
#fig.add_axes(ax_r)
47-
#fig.add_axes(ax_g)
48-
#fig.add_axes(ax_b)
45+
# fig.add_axes(ax_r)
46+
# fig.add_axes(ax_g)
47+
# fig.add_axes(ax_b)
4948

5049
r, g, b = get_rgb()
5150
im_r, im_g, im_b, im_rgb = make_cube(r, g, b)
@@ -56,13 +55,11 @@ def demo_rgb():
5655
ax_b.imshow(im_b, **kwargs)
5756

5857

59-
60-
6158
def demo_rgb2():
6259
fig = plt.figure(2)
6360
ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8], pad=0.0)
64-
#fig.add_axes(ax)
65-
#ax.add_RGB_to_figure()
61+
# fig.add_axes(ax)
62+
# ax.add_RGB_to_figure()
6663

6764
r, g, b = get_rgb()
6865
kwargs = dict(origin="lower", interpolation="nearest")

examples/axes_grid/demo_colorbar_with_inset_locator.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[6, 3])
66

77
axins1 = inset_axes(ax1,
8-
width="50%", # width = 10% of parent_bbox width
9-
height="5%", # height : 50%
8+
width="50%", # width = 10% of parent_bbox width
9+
height="5%", # height : 50%
1010
loc=1)
1111

12-
im1=ax1.imshow([[1,2],[2, 3]])
13-
plt.colorbar(im1, cax=axins1, orientation="horizontal", ticks=[1,2,3])
12+
im1 = ax1.imshow([[1, 2], [2, 3]])
13+
plt.colorbar(im1, cax=axins1, orientation="horizontal", ticks=[1, 2, 3])
1414
axins1.xaxis.set_ticks_position("bottom")
1515

1616
axins = inset_axes(ax2,
17-
width="5%", # width = 10% of parent_bbox width
18-
height="50%", # height : 50%
17+
width="5%", # width = 10% of parent_bbox width
18+
height="50%", # height : 50%
1919
loc=3,
2020
bbox_to_anchor=(1.05, 0., 1, 1),
2121
bbox_transform=ax2.transAxes,
@@ -26,8 +26,8 @@
2626
# of the legend. you may want to play with the borderpad value and
2727
# the bbox_to_anchor coordinate.
2828

29-
im=ax2.imshow([[1,2],[2, 3]])
30-
plt.colorbar(im, cax=axins, ticks=[1,2,3])
29+
im = ax2.imshow([[1, 2], [2, 3]])
30+
plt.colorbar(im, cax=axins, ticks=[1, 2, 3])
3131

3232
plt.draw()
3333
plt.show()

0 commit comments

Comments
 (0)