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

Skip to content

Commit 34056bf

Browse files
committed
PEP8 for colormap_normalizations.py
1 parent 6188d71 commit 34056bf

1 file changed

Lines changed: 51 additions & 44 deletions

File tree

examples/color/colormap_normalizations.py

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
# A low hump with a spike coming out of the top right. Needs to have
1818
# z/colour axis on a log scale so we see both hump and spike. linear
1919
# scale only shows the spike.
20-
Z1 = bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) + 0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
20+
Z1 = bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) + \
21+
0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
2122

22-
fig,ax=plt.subplots(2,1)
23+
fig, ax = plt.subplots(2, 1)
2324

24-
pcm=ax[0].pcolor(X, Y, Z1, norm=colors.LogNorm(vmin=Z1.min(), vmax=Z1.max()), cmap='PuBu_r')
25-
fig.colorbar(pcm,ax=ax[0],extend='max')
25+
pcm = ax[0].pcolor(X, Y, Z1,
26+
norm=colors.LogNorm(vmin=Z1.min(), vmax=Z1.max()),
27+
cmap='PuBu_r')
28+
fig.colorbar(pcm, ax=ax[0], extend='max')
2629

27-
pcm=ax[1].pcolor(X, Y, Z1, cmap='PuBu_r')
28-
fig.colorbar(pcm,ax=ax[1],extend='max')
30+
pcm = ax[1].pcolor(X, Y, Z1, cmap='PuBu_r')
31+
fig.colorbar(pcm, ax=ax[1], extend='max')
2932
fig.show()
3033

3134

@@ -36,16 +39,16 @@
3639
X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)]
3740
Z1 = (1+np.sin(Y*10.))*X**(2.)
3841

39-
fig,ax=plt.subplots(2,1)
42+
fig, ax = plt.subplots(2, 1)
4043

41-
pcm=ax[0].pcolormesh(X, Y, Z1, norm=colors.PowerNorm(gamma=1./2.), cmap='PuBu_r')
42-
fig.colorbar(pcm,ax=ax[0],extend='max')
44+
pcm = ax[0].pcolormesh(X, Y, Z1, norm=colors.PowerNorm(gamma=1./2.),
45+
cmap='PuBu_r')
46+
fig.colorbar(pcm, ax=ax[0], extend='max')
4347

44-
pcm=ax[1].pcolormesh(X, Y, Z1, cmap='PuBu_r')
45-
fig.colorbar(pcm,ax=ax[1],extend='max')
48+
pcm = ax[1].pcolormesh(X, Y, Z1, cmap='PuBu_r')
49+
fig.colorbar(pcm, ax=ax[1], extend='max')
4650
fig.show()
4751

48-
4952
'''
5053
SymLogNorm: two humps, one negative and one positive, The positive
5154
with 5-times the amplitude. Linearly, you cannot see detail in the
@@ -56,20 +59,20 @@
5659
'''
5760

5861
X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]
59-
Z1 = (bivariate_normal(X, Y, 1.,1., 1.0, 1.0))**2 \
62+
Z1 = (bivariate_normal(X, Y, 1., 1., 1.0, 1.0))**2 \
6063
- 0.4 * (bivariate_normal(X, Y, 1.0, 1.0, -1.0, 0.0))**2
6164
Z1 = Z1/0.03
6265

63-
fig,ax=plt.subplots(2,1)
66+
fig, ax = plt.subplots(2, 1)
6467

65-
pcm=ax[0].pcolormesh(X, Y, Z1,
66-
norm=colors.SymLogNorm(linthresh=0.03,linscale=0.03,
67-
vmin=-1.0,vmax=1.0),
68-
cmap='RdBu_r')
69-
fig.colorbar(pcm,ax=ax[0],extend='both')
68+
pcm = ax[0].pcolormesh(X, Y, Z1,
69+
norm=colors.SymLogNorm(linthresh=0.03, linscale=0.03,
70+
vmin=-1.0, vmax=1.0),
71+
cmap='RdBu_r')
72+
fig.colorbar(pcm, ax=ax[0], extend='both')
7073

71-
pcm=ax[1].pcolormesh(X, Y, Z1, cmap='RdBu_r',vmin=-np.max(Z1))
72-
fig.colorbar(pcm,ax=ax[1],extend='both')
74+
pcm = ax[1].pcolormesh(X, Y, Z1, cmap='RdBu_r', vmin=-np.max(Z1))
75+
fig.colorbar(pcm, ax=ax[1], extend='both')
7376
fig.show()
7477

7578

@@ -79,31 +82,34 @@
7982
from the positive.
8083
'''
8184
X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)]
82-
Z1 = (bivariate_normal(X, Y, 1.,1., 1.0, 1.0))**2 \
85+
Z1 = (bivariate_normal(X, Y, 1., 1., 1.0, 1.0))**2 \
8386
- 0.4 * (bivariate_normal(X, Y, 1.0, 1.0, -1.0, 0.0))**2
8487
Z1 = Z1/0.03
8588

8689
# Example of making your own norm. Also see matplotlib.colors.
8790
# From Joe Kington: This one gives two different linear ramps:
91+
92+
8893
class MidpointNormalize(colors.Normalize):
8994
def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
9095
self.midpoint = midpoint
9196
colors.Normalize.__init__(self, vmin, vmax, clip)
97+
9298
def __call__(self, value, clip=None):
9399
# I'm ignoring masked values and all kinds of edge cases to make a
94100
# simple example...
95101
x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1]
96102
return np.ma.masked_array(np.interp(value, x, y))
97103
#####
98-
fig,ax=plt.subplots(2,1)
104+
fig, ax = plt.subplots(2, 1)
99105

100-
pcm=ax[0].pcolormesh(X, Y, Z1,
101-
norm=MidpointNormalize(midpoint=0.),
102-
cmap='RdBu_r')
103-
fig.colorbar(pcm,ax=ax[0],extend='both')
106+
pcm = ax[0].pcolormesh(X, Y, Z1,
107+
norm=MidpointNormalize(midpoint=0.),
108+
cmap='RdBu_r')
109+
fig.colorbar(pcm, ax=ax[0], extend='both')
104110

105-
pcm=ax[1].pcolormesh(X, Y, Z1, cmap='RdBu_r',vmin=-np.max(Z1))
106-
fig.colorbar(pcm,ax=ax[1],extend='both')
111+
pcm = ax[1].pcolormesh(X, Y, Z1, cmap='RdBu_r', vmin=-np.max(Z1))
112+
fig.colorbar(pcm, ax=ax[1], extend='both')
107113
fig.show()
108114

109115
'''
@@ -112,22 +118,23 @@ def __call__(self, value, clip=None):
112118
second color between the second pair, etc.
113119
'''
114120

115-
fig,ax=plt.subplots(3,1,figsize=(8,8))
116-
ax=ax.flatten()
121+
fig, ax = plt.subplots(3, 1, figsize=(8, 8))
122+
ax = ax.flatten()
117123
# even bounds gives a contour-like effect
118-
bounds= np.linspace(-1,1,10)
119-
pcm=ax[0].pcolormesh(X, Y, Z1,
120-
norm=colors.BoundaryNorm(boundaries=bounds,ncolors=256),
121-
cmap='RdBu_r')
122-
fig.colorbar(pcm,ax=ax[0],extend='both',orientation='vertical')
124+
bounds = np.linspace(-1, 1, 10)
125+
norm = colors.BoundaryNorm(boundaries=bounds, ncolors=256)
126+
pcm = ax[0].pcolormesh(X, Y, Z1,
127+
norm=norm,
128+
cmap='RdBu_r')
129+
fig.colorbar(pcm, ax=ax[0], extend='both', orientation='vertical')
123130

124131
# uneven bounds changes the colormapping:
125-
bounds = np.array([-0.25,-0.125,0,0.5,1])
126-
pcm=ax[1].pcolormesh(X, Y, Z1,
127-
norm=colors.BoundaryNorm(boundaries=bounds,ncolors=256),
128-
cmap='RdBu_r')
129-
fig.colorbar(pcm,ax=ax[1],extend='both',orientation='vertical')
130-
131-
pcm=ax[2].pcolormesh(X, Y, Z1, cmap='RdBu_r',vmin=-np.max(Z1))
132-
fig.colorbar(pcm,ax=ax[2],extend='both',orientation='vertical')
132+
bounds = np.array([-0.25, -0.125, 0, 0.5, 1])
133+
norm = colors.BoundaryNorm(boundaries=bounds, ncolors=256)
134+
pcm = ax[1].pcolormesh(X, Y, Z1, norm=norm, cmap='RdBu_r')
135+
fig.colorbar(pcm, ax=ax[1], extend='both', orientation='vertical')
136+
137+
pcm = ax[2].pcolormesh(X, Y, Z1, cmap='RdBu_r', vmin=-np.max(Z1))
138+
fig.colorbar(pcm, ax=ax[2], extend='both', orientation='vertical')
133139
fig.show()
140+

0 commit comments

Comments
 (0)