Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf24cbca

Browse files
committed
hypot / **2 instead of x * x
1 parentea968ed commitf24cbca

30 files changed

+128
-141
lines changed

‎examples/animation/unchained.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Generate random data
2626
data=np.random.uniform(0,1, (64,75))
2727
X=np.linspace(-1,1,data.shape[-1])
28-
G=1.5*np.exp(-4*X*X)
28+
G=1.5*np.exp(-4*X**2)
2929

3030
# Generate line plots
3131
lines= []

‎examples/api/custom_projection_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ def transform_non_affine(self, xy):
440440

441441
quarter_x=0.25*x
442442
half_y=0.5*y
443-
z=np.sqrt(1.0-quarter_x*quarter_x-half_y*half_y)
444-
longitude=2*np.arctan((z*x)/ (2.0* (2.0*z*z-1.0)))
443+
z=np.sqrt(1-quarter_x*quarter_x-half_y*half_y)
444+
longitude=2*np.arctan((z*x)/ (2* (2*z**2-1)))
445445
latitude=np.arcsin(y*z)
446446
returnnp.concatenate((longitude,latitude),1)
447447
transform_non_affine.__doc__=Transform.transform_non_affine.__doc__

‎examples/api/scatter_piecharts.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
Thanks to Manuel Metz for the example
99
"""
10-
importmath
10+
1111
importnumpyasnp
1212
importmatplotlib.pyplotasplt
1313

@@ -16,35 +16,33 @@
1616
r2=r1+0.4# 40%
1717

1818
# define some sizes of the scatter marker
19-
sizes= [60,80,120]
19+
sizes=np.array([60,80,120])
2020

2121
# calculate the points of the first pie marker
2222
#
2323
# these are just the origin (0,0) +
2424
# some points on a circle cos,sin
25-
x= [0]+np.cos(np.linspace(0,2*math.pi*r1,10)).tolist()
26-
y= [0]+np.sin(np.linspace(0,2*math.pi*r1,10)).tolist()
27-
25+
x= [0]+np.cos(np.linspace(0,2*np.pi*r1,10)).tolist()
26+
y= [0]+np.sin(np.linspace(0,2*np.pi*r1,10)).tolist()
2827
xy1=list(zip(x,y))
29-
s1=max(max(x),max(y))
28+
s1=np.max(xy1)
3029

31-
# ...
32-
x= [0]+np.cos(np.linspace(2*math.pi*r1,2*math.pi*r2,10)).tolist()
33-
y= [0]+np.sin(np.linspace(2*math.pi*r1,2*math.pi*r2,10)).tolist()
30+
x= [0]+np.cos(np.linspace(2*np.pi*r1,2*np.pi*r2,10)).tolist()
31+
y= [0]+np.sin(np.linspace(2*np.pi*r1,2*np.pi*r2,10)).tolist()
3432
xy2=list(zip(x,y))
35-
s2=max(max(x),max(y))
33+
s2=np.max(xy2)
3634

37-
x= [0]+np.cos(np.linspace(2*math.pi*r2,2*math.pi,10)).tolist()
38-
y= [0]+np.sin(np.linspace(2*math.pi*r2,2*math.pi,10)).tolist()
35+
x= [0]+np.cos(np.linspace(2*np.pi*r2,2*np.pi,10)).tolist()
36+
y= [0]+np.sin(np.linspace(2*np.pi*r2,2*np.pi,10)).tolist()
3937
xy3=list(zip(x,y))
40-
s3=max(max(x),max(y))
38+
s3=np.max(xy3)
4139

4240
fig,ax=plt.subplots()
43-
ax.scatter(np.arange(3),np.arange(3),marker=(xy1,0),
44-
s=[s1*s1*_for_insizes],facecolor='blue')
45-
ax.scatter(np.arange(3),np.arange(3),marker=(xy2,0),
46-
s=[s2*s2*_for_insizes],facecolor='green')
47-
ax.scatter(np.arange(3),np.arange(3),marker=(xy3,0),
48-
s=[s3*s3*_for_insizes],facecolor='red')
41+
ax.scatter(range(3),range(3),marker=(xy1,0),
42+
s=s1**2*sizes,facecolor='blue')
43+
ax.scatter(range(3),range(3),marker=(xy2,0),
44+
s=s2**2*sizes,facecolor='green')
45+
ax.scatter(range(3),range(3),marker=(xy3,0),
46+
s=s3**2*sizes,facecolor='red')
4947

5048
plt.show()

‎examples/event_handling/timers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def update_title(axes):
1212
fig,ax=plt.subplots()
1313

1414
x=np.linspace(-3,3)
15-
ax.plot(x,x*x)
15+
ax.plot(x,x**2)
1616

1717
# Create a new timer object. Set the interval to 100 milliseconds
1818
# (1000 is default) and tell the timer what function should be called.

‎examples/event_handling/trifinder_event_demo.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@ def motion_notify(event):
3535
n_radii=5
3636
min_radius=0.25
3737
radii=np.linspace(min_radius,0.95,n_radii)
38-
angles=np.linspace(0,2*math.pi,n_angles,endpoint=False)
38+
angles=np.linspace(0,2*math.pi,n_angles,endpoint=False)
3939
angles=np.repeat(angles[...,np.newaxis],n_radii,axis=1)
4040
angles[:,1::2]+=math.pi/n_angles
41-
x= (radii*np.cos(angles)).flatten()
42-
y= (radii*np.sin(angles)).flatten()
41+
x= (radii*np.cos(angles)).flatten()
42+
y= (radii*np.sin(angles)).flatten()
4343
triangulation=Triangulation(x,y)
44-
xmid=x[triangulation.triangles].mean(axis=1)
45-
ymid=y[triangulation.triangles].mean(axis=1)
46-
mask=np.where(xmid*xmid+ymid*ymid<min_radius*min_radius,1,0)
47-
triangulation.set_mask(mask)
44+
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
45+
y[triang.triangles].mean(axis=1))
46+
<min_radius)
4847

4948
# Use the triangulation's default TriFinder object.
5049
trifinder=triangulation.get_trifinder()

‎examples/mplot3d/tricontour3d_demo.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,21 @@
2020

2121
# Create the mesh in polar coordinates and compute x, y, z.
2222
radii=np.linspace(min_radius,0.95,n_radii)
23-
angles=np.linspace(0,2*np.pi,n_angles,endpoint=False)
23+
angles=np.linspace(0,2*np.pi,n_angles,endpoint=False)
2424
angles=np.repeat(angles[...,np.newaxis],n_radii,axis=1)
25-
angles[:,1::2]+=np.pi/n_angles
25+
angles[:,1::2]+=np.pi/n_angles
2626

27-
x= (radii*np.cos(angles)).flatten()
28-
y= (radii*np.sin(angles)).flatten()
29-
z= (np.cos(radii)*np.cos(angles*3.0)).flatten()
27+
x= (radii*np.cos(angles)).flatten()
28+
y= (radii*np.sin(angles)).flatten()
29+
z= (np.cos(radii)*np.cos(3*angles)).flatten()
3030

3131
# Create a custom triangulation.
3232
triang=tri.Triangulation(x,y)
3333

3434
# Mask off unwanted triangles.
35-
xmid=x[triang.triangles].mean(axis=1)
36-
ymid=y[triang.triangles].mean(axis=1)
37-
mask=np.where(xmid*xmid+ymid*ymid<min_radius*min_radius,1,0)
38-
triang.set_mask(mask)
35+
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
36+
y[triang.triangles].mean(axis=1))
37+
<min_radius)
3938

4039
fig=plt.figure()
4140
ax=fig.gca(projection='3d')

‎examples/mplot3d/tricontourf3d_demo.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,21 @@
2121

2222
# Create the mesh in polar coordinates and compute x, y, z.
2323
radii=np.linspace(min_radius,0.95,n_radii)
24-
angles=np.linspace(0,2*np.pi,n_angles,endpoint=False)
24+
angles=np.linspace(0,2*np.pi,n_angles,endpoint=False)
2525
angles=np.repeat(angles[...,np.newaxis],n_radii,axis=1)
26-
angles[:,1::2]+=np.pi/n_angles
26+
angles[:,1::2]+=np.pi/n_angles
2727

28-
x= (radii*np.cos(angles)).flatten()
29-
y= (radii*np.sin(angles)).flatten()
30-
z= (np.cos(radii)*np.cos(angles*3.0)).flatten()
28+
x= (radii*np.cos(angles)).flatten()
29+
y= (radii*np.sin(angles)).flatten()
30+
z= (np.cos(radii)*np.cos(3*angles)).flatten()
3131

3232
# Create a custom triangulation.
3333
triang=tri.Triangulation(x,y)
3434

3535
# Mask off unwanted triangles.
36-
xmid=x[triang.triangles].mean(axis=1)
37-
ymid=y[triang.triangles].mean(axis=1)
38-
mask=np.where(xmid*xmid+ymid*ymid<min_radius*min_radius,1,0)
39-
triang.set_mask(mask)
36+
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
37+
y[triang.triangles].mean(axis=1))
38+
<min_radius)
4039

4140
fig=plt.figure()
4241
ax=fig.gca(projection='3d')

‎examples/mplot3d/trisurf3d_demo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616

1717
# Make radii and angles spaces (radius r=0 omitted to eliminate duplication).
1818
radii=np.linspace(0.125,1.0,n_radii)
19-
angles=np.linspace(0,2*np.pi,n_angles,endpoint=False)
19+
angles=np.linspace(0,2*np.pi,n_angles,endpoint=False)
2020

2121
# Repeat all angles for each radius.
2222
angles=np.repeat(angles[...,np.newaxis],n_radii,axis=1)
2323

2424
# Convert polar (radii, angles) coords to cartesian (x, y) coords.
2525
# (0, 0) is manually added at this stage, so there will be no duplicate
2626
# points in the (x, y) plane.
27-
x=np.append(0, (radii*np.cos(angles)).flatten())
28-
y=np.append(0, (radii*np.sin(angles)).flatten())
27+
x=np.append(0, (radii*np.cos(angles)).flatten())
28+
y=np.append(0, (radii*np.sin(angles)).flatten())
2929

3030
# Compute z to make the pringle surface.
31-
z=np.sin(-x*y)
31+
z=np.sin(-x*y)
3232

3333
fig=plt.figure()
3434
ax=fig.gca(projection='3d')

‎examples/mplot3d/trisurf3d_demo2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@
5454
min_radius=0.25
5555
radii=np.linspace(min_radius,0.95,n_radii)
5656

57-
angles=np.linspace(0,2*np.pi,n_angles,endpoint=False)
57+
angles=np.linspace(0,2*np.pi,n_angles,endpoint=False)
5858
angles=np.repeat(angles[...,np.newaxis],n_radii,axis=1)
5959
angles[:,1::2]+=np.pi/n_angles
6060

6161
# Map radius, angle pairs to x, y, z points.
62-
x= (radii*np.cos(angles)).flatten()
63-
y= (radii*np.sin(angles)).flatten()
64-
z= (np.cos(radii)*np.cos(angles*3.0)).flatten()
62+
x= (radii*np.cos(angles)).flatten()
63+
y= (radii*np.sin(angles)).flatten()
64+
z= (np.cos(radii)*np.cos(3*angles)).flatten()
6565

6666
# Create the Triangulation; no triangles so Delaunay triangulation created.
6767
triang=mtri.Triangulation(x,y)

‎examples/pylab_examples/annotation_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
fig=plt.figure()
9292
ax=fig.add_subplot(111,projection='polar')
9393
r=np.arange(0,1,0.001)
94-
theta=2*2*np.pi*r
94+
theta=4*np.pi*r
9595
line,=ax.plot(theta,r)
9696

9797
ind=800

‎examples/pylab_examples/cursor_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def mouse_move(self, event):
7474
plt.draw()
7575

7676
t=np.arange(0.0,1.0,0.01)
77-
s=np.sin(2*2*np.pi*t)
77+
s=np.sin(4*np.pi*t)
7878
fig,ax=plt.subplots()
7979

8080
#cursor = Cursor(ax)

‎examples/pylab_examples/date_demo_convert.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
importdatetime
22
importmatplotlib.pyplotasplt
33
frommatplotlib.datesimportDayLocator,HourLocator,DateFormatter,drange
4-
fromnumpyimportarange
4+
importnumpyasnp
55

66
date1=datetime.datetime(2000,3,2)
77
date2=datetime.datetime(2000,3,6)
88
delta=datetime.timedelta(hours=6)
99
dates=drange(date1,date2,delta)
1010

11-
y=arange(len(dates)*1.0)
11+
y=np.arange(len(dates))
1212

1313
fig,ax=plt.subplots()
14-
ax.plot_date(dates,y*y)
14+
ax.plot_date(dates,y**2)
1515

1616
# this is superfluous, since the autoscaler should get it right, but
1717
# use date2num and num2date to convert between dates and floats if
@@ -22,7 +22,7 @@
2222
# tick, not the base multiple
2323

2424
ax.xaxis.set_major_locator(DayLocator())
25-
ax.xaxis.set_minor_locator(HourLocator(arange(0,25,6)))
25+
ax.xaxis.set_minor_locator(HourLocator(range(0,25,6)))
2626
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
2727

2828
ax.fmt_xdata=DateFormatter('%Y-%m-%d %H:%M:%S')

‎examples/pylab_examples/equal_aspect_ratio.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
importnumpyasnp
77

88
t=np.arange(0.0,1.0+0.01,0.01)
9-
s=np.cos(2*2*np.pi*t)
9+
s=np.cos(4*np.pi*t)
1010
plt.plot(t,s,'-',lw=2)
1111

1212
plt.xlabel('time (s)')
@@ -16,5 +16,4 @@
1616

1717
plt.axes().set_aspect('equal','datalim')
1818

19-
2019
plt.show()

‎examples/pylab_examples/multipage_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
plt.rc('text',usetex=False)
3333
fig=plt.figure(figsize=(4,5))
34-
plt.plot(x,x*x,'ko')
34+
plt.plot(x,x**2,'ko')
3535
plt.title('Page Three')
3636
pdf.savefig(fig)# or you can pass a Figure object to pdf.savefig
3737
plt.close()

‎examples/pylab_examples/nan_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
importmatplotlib.pyplotasplt
66

77
t=np.arange(0.0,1.0+0.01,0.01)
8-
s=np.cos(2*2*np.pi*t)
8+
s=np.cos(4*np.pi*t)
99
t[41:60]=np.nan
1010

1111
plt.subplot(2,1,1)

‎examples/pylab_examples/pythonic_matplotlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171

7272

7373
ax2=fig.add_subplot(212)
74-
ax2.plot(t,sin(2*2*pi*t))
74+
ax2.plot(t,sin(4*pi*t))
7575
ax2.grid(True)
7676
ax2.set_ylim((-2,2))
7777
l=ax2.set_xlabel('Hi mom')

‎examples/pylab_examples/scatter_masked.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
N=100
99
r0=0.6
10-
x=0.9*np.random.rand(N)
11-
y=0.9*np.random.rand(N)
12-
area=np.pi*(10*np.random.rand(N))**2# 0 to 10 point radiuses
10+
x=0.9*np.random.rand(N)
11+
y=0.9*np.random.rand(N)
12+
area=np.pi*(10*np.random.rand(N))**2# 0 to 10 point radiuses
1313
c=np.sqrt(area)
14-
r=np.sqrt(x*x+y*y)
14+
r=np.sqrt(x*x+y*y)
1515
area1=np.ma.masked_where(r<r0,area)
1616
area2=np.ma.masked_where(r>=r0,area)
1717
plt.scatter(x,y,s=area1,marker='^',c=c)
1818
plt.scatter(x,y,s=area2,marker='o',c=c)
1919
# Show the boundary between the regions:
20-
theta=np.arange(0,np.pi/2,0.01)
21-
plt.plot(r0*np.cos(theta),r0*np.sin(theta))
20+
theta=np.arange(0,np.pi/2,0.01)
21+
plt.plot(r0*np.cos(theta),r0*np.sin(theta))
2222

2323
plt.show()

‎examples/pylab_examples/stackplot_demo2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def bump(a):
1515
z=10/ (.1+np.random.random())
1616
foriinrange(m):
1717
w= (i/float(m)-y)*z
18-
a[i]+=x*np.exp(-w*w)
18+
a[i]+=x*np.exp(-w**2)
1919
a=np.zeros((m,n))
2020
foriinrange(n):
2121
forjinrange(5):

‎examples/pylab_examples/tex_unicode_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
plt.figure(1,figsize=(6,4))
1515
ax=plt.axes([0.1,0.1,0.8,0.7])
1616
t=np.arange(0.0,1.0+0.01,0.01)
17-
s=np.cos(2*2*np.pi*t)+2
17+
s=np.cos(4*np.pi*t)+2
1818
plt.plot(t,s)
1919

2020
plt.xlabel(r'\textbf{time (s)}')

‎examples/pylab_examples/tricontour_demo.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,21 @@
1515
min_radius=0.25
1616
radii=np.linspace(min_radius,0.95,n_radii)
1717

18-
angles=np.linspace(0,2*math.pi,n_angles,endpoint=False)
18+
angles=np.linspace(0,2*math.pi,n_angles,endpoint=False)
1919
angles=np.repeat(angles[...,np.newaxis],n_radii,axis=1)
20-
angles[:,1::2]+=math.pi/n_angles
20+
angles[:,1::2]+=math.pi/n_angles
2121

22-
x= (radii*np.cos(angles)).flatten()
23-
y= (radii*np.sin(angles)).flatten()
24-
z= (np.cos(radii)*np.cos(angles*3.0)).flatten()
22+
x= (radii*np.cos(angles)).flatten()
23+
y= (radii*np.sin(angles)).flatten()
24+
z= (np.cos(radii)*np.cos(3*angles)).flatten()
2525

2626
# Create the Triangulation; no triangles so Delaunay triangulation created.
2727
triang=tri.Triangulation(x,y)
2828

2929
# Mask off unwanted triangles.
30-
xmid=x[triang.triangles].mean(axis=1)
31-
ymid=y[triang.triangles].mean(axis=1)
32-
mask=np.where(xmid*xmid+ymid*ymid<min_radius*min_radius,1,0)
33-
triang.set_mask(mask)
30+
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
31+
y[triang.triangles].mean(axis=1))
32+
<min_radius)
3433

3534
# pcolor plot.
3635
plt.figure()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp