8000 PEP8 formatting on examples, plotting using the object oriented appro… · matplotlib/matplotlib@57aad3d · GitHub
[go: up one dir, main page]

Skip to content

Commit 57aad3d

Browse files
alvarosgalvarosg
authored andcommitted
PEP8 formatting on examples, plotting using the object oriented approach, test matrix data improved
1 parent 2d90c5a commit 57aad3d

File tree

2 files changed

+113
-98
lines changed

2 files changed

+113
-98
lines changed

doc/users/plotting/examples/colormap_normalizations_arbitrarynorm.py

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,64 @@
77
import matplotlib.pyplot as plt
88
import matplotlib.cm as cm
99

10-
x=np.linspace(0,16*np.pi,1024)
11-
y=np.linspace(-1,1,512)
12-
X,Y=np.meshgrid(x,y)
13-
14-
data=np.zeros(X.shape)
15-
16-
data[Y>0]=np.cos(X[Y>0])*Y[Y>0]**2
17-
18-
for i,val in enumerate(np.arange(-1,1.1,0.2)):
19-
if val<0:data[(X>(i*(50./11)))*(Y<0)]=val
20-
if val>0:data[(X>(i*(50./11)))*(Y<0)]=val*2
21-
22-
figsize=(16,10)
23-
cmap=cm.gist_rainbow
24-
25-
plt.figure(figsize=figsize)
26-
plt.pcolormesh(x,y,data,cmap=cmap)
27-
plt.title('Linear Scale')
28-
plt.colorbar(format='%.3g')
29-
plt.xlim(0,16*np.pi)
30-
plt.ylim(-1,1)
31-
32-
plt.figure(figsize=figsize)
33-
norm=colors.ArbitraryNorm(fpos=(lambda x: x**0.2),
34-
fposinv=(lambda x: x**5),
35-
fneg=(lambda x: x**0.5),
36-
fneginv=(lambda x: x**2),
37-
center=0.4)
38-
plt.pcolormesh(x,y,data,cmap=cmap,norm=norm)
39-
plt.title('Arbitrary norm')
40-
plt.colorbar(ticks=norm.ticks(),format='%.3g')
41-
plt.xlim(0,16*np.pi)
42-
plt.ylim(-1,1)
43-
44-
plt.figure(figsize=figsize)
45-
norm=colors.PositiveArbitraryNorm(vmin=0,
46-
fpos=(lambda x: x**0.5),
47-
fposinv=(lambda x: x**2))
48-
plt.pcolormesh(x,y,data,cmap=cmap,norm=norm)
49-
plt.title('Positive arbitrary norm')
50-
plt.colorbar(ticks=norm.ticks(),format='%.3g')
51-
plt.xlim(0,16*np.pi)
52-
plt.ylim(-1,1)
53-
54-
plt.figure(figsize=figsize)
55-
norm=colors.NegativeArbitraryNorm(vmax=0,
56-
fneg=(lambda x: x**0.5),
57-
fneginv=(lambda x: x**2))
58-
plt.pcolormesh(x,y,data,cmap=cmap,norm=norm)
59-
plt.title('Negative arbitrary norm')
60-
plt.colorbar(ticks=norm.ticks(),format='%.3g')
61-
plt.xlim(0,16*np.pi)
62-
plt.ylim(-1,1)
10+
xmax = 16 * np.pi
11+
x = np.linspace(0, xmax, 1024)
12+
y = np.linspace(-2, 1, 512)
13+
X, Y = np.meshgrid(x, y)
14+
15+
data = np.zeros(X.shape)
16+
17+
18+
def gauss2d(x, y, a0, x0, y0, wx, wy):
19+
return a0 * np.exp(-(x - x0)**2 / wx**2 - (y - y0)**2 / wy**2)
20+
21+
N = 61
22+
for i in range(N):
23+
data = data + gauss2d(X, Y, 2. * i / N, i *
24+
(xmax / N), -0.25, xmax / (3 * N), 0.07)
25+
data = data - gauss2d(X, Y, 1. * i / N, i *
26+
(xmax / N), -0.75, xmax / (3 * N), 0.07)
27+
28+
data[Y > 0] = np.cos(X[Y > 0]) * Y[Y > 0]**2
29+
30+
N = 61
31+
for i, val in enumerate(np.linspace(-1, 1, N)):
32+
if val < 0:
33+
aux = val
34+
if val > 0:
35+
aux = val * 2
36+
data[(X > (i * (xmax / N))) * (Y < -1)] = aux
37+
38+
39+
cmap = cm.gist_rainbow
40+
41+
norms = [('Linear Scale', None),
42+
('Arbitrary norm',
43+
colors.ArbitraryNorm(fpos=(lambda x: x**0.2),
44+
fposinv=(lambda x: x**5),
45+
fneg=(lambda x: x**0.5),
46+
fneginv=(lambda x: x**2),
47+
center=0.4)),
48+
('Positive arbitrary norm',
49+
colors.PositiveArbitraryNorm(vmin=0,
50+
fpos=(lambda x: x**0.5),
51+
fposinv=(lambda x: x**2))),
52+
('Negative arbitrary norm',
53+
colors.NegativeArbitraryNorm(vmax=0,
54+
fneg=(lambda x: x**0.5),
55+
fneginv=(lambda x: x**2)))]
56+
57+
58+
for label, norm in norms:
59+
fig, ax = plt.subplots()
60+
cax = ax.pcolormesh(x, y, data, cmap=cmap, norm=norm)
61+
ax.set_title(label)
62+
ax.set_xlim(0, xmax)
63+
ax.set_ylim(-2, 1)
64+
if norm:
65+
ticks = norm.ticks()
66+
else:
67+
ticks = None
68+
cbar = fig.colorbar(cax, format='%.3g', ticks=ticks)
69+
70+
plt.show()

doc/users/plotting/examples/colormap_normalizations_rootnorm.py

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,55 @@
77
import matplotlib.pyplot as plt
88
import matplotlib.cm as cm
99

10-
x=np.linspace(0,16*np.pi,1024)
11-
y=np.linspace(-1,1,512)
12-
X,Y=np.meshgrid(x,y)
13-
14-
data=np.zeros(X.shape)
15-
16-
data[Y>0]=np.cos(X[Y>0])*Y[Y>0]**2
17-
18-
for i,val in enumerate(np.arange(-1,1.1,0.2)):
19-
if val<0:data[(X>(i*(50./11)))*(Y<0)]=val
20-
if val>0:data[(X>(i*(50./11)))*(Y<0)]=val*2
21-
22-
figsize=(16,10)
23-
cmap=cm.gist_rainbow
24-
25-
plt.figure(figsize=figsize)
26-
plt.pcolormesh(x,y,data,cmap=cmap)
27-
plt.title('Linear Scale')
28-
plt.colorbar(format='%.3g')
29-
plt.xlim(0,16*np.pi)
30-
plt.ylim(-1,1)
31-
32-
plt.figure(figsize=figsize)
33-
norm=colors.SymRootNorm(orderpos=7,orderneg=2,center=0.3)
34-
plt.pcolormesh(x,y,data,cmap=cmap,norm=norm)
35-
plt.title('Symmetric root norm')
36-
plt.colorbar(ticks=norm.ticks(),format='%.3g')
37-
plt.xlim(0,16*np.pi)
38-
plt.ylim(-1,1)
39-
40-
plt.figure(figsize=figsize)
41-
norm=colors.PositiveRootNorm(vmin=0,orderpos=5)
42-
plt.pcolormesh(x,y,data,cmap=cmap,norm=norm)
43-
plt.title('Positive root norm')
44-
plt.colorbar(ticks=norm.ticks(),format='%.3g')
45-
plt.xlim(0,16*np.pi)
46-
plt.ylim(-1,1)
47-
48-
plt.figure(figsize=figsize)
49-
norm=colors.NegativeRootNorm(vmax=0,orderneg=5)
50-
plt.pcolormesh(x,y,data,cmap=cmap,norm=norm)
51-
plt.title('Negative root norm')
52-
plt.colorbar(ticks=norm.ticks(),format='%.3g')
53-
plt.xlim(0,16*np.pi)
54-
plt.ylim(-1,1)
10+
xmax = 16 * np.pi
11+
x = np.linspace(0, xmax, 1024)
12+
y = np.linspace(-2, 1, 512)
13+
X, Y = np.meshgrid(x, y)
14+
15+
data = np.zeros(X.shape)
16+
17+
18+
def gauss2d(x, y, a0, x0, y0, wx, wy):
19+
return a0 * np.exp(-(x - x0)**2 / wx**2 - (y - y0)**2 / wy**2)
20+
21+
N = 61
22+
for i in range(N):
23+
data = data + gauss2d(X, Y, 2. * i / N, i *
24+
(xmax / N), -0.25, xmax / (3 * N), 0.07)
25+
data = data - gauss2d(X, Y, 1. * i / N, i *
26+
(xmax / N), -0.75, xmax / (3 * N), 0.07)
27+
28+
data[Y > 0] = np.cos(X[Y > 0]) * Y[Y > 0]**2
29+
30+
N = 61
31+
for i, val in enumerate(np.linspace(-1, 1, N)):
32+
if val < 0:
33+
aux = val
34+
if val > 0:
35+
aux = val * 2
36+
data[(X > (i * (xmax / N))) * (Y < -1)] = aux
37+
38+
cmap = cm.gist_rainbow
39+
40+
norms = [('Linear Scale', None),
41+
('Symmetric root norm',
42+
colors.SymRootNorm(orderpos=7, orderneg=2, center=0.3)),
43+
('Positive root norm',
44+
colors.PositiveRootNorm(vmin=0, orderpos=5)),
45+
('Negative root norm',
46+
colors.NegativeRootNorm(vmax=0, orderneg=5))]
47+
48+
49+
for label, norm in norms:
50+
fig, ax = plt.subplots()
51+
cax = ax.pcolormesh(x, y, data, cmap=cmap, norm=norm)
52+
ax.set_title(label)
53+
ax.set_xlim(0, xmax)
54+
ax.set_ylim(-2, 1)
55+
if norm:
56+
ticks = norm.ticks()
57+
else:
58+
ticks = None
59+
cbar = fig.colorbar(cax, format='%.3g', ticks=ticks)
60+
61+
plt.show()

0 commit comments

Comments
 (0)
0