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

Skip to content

Commit 0f9decf

Browse files
committed
Improve speed
1 parent 42b798c commit 0f9decf

File tree

6 files changed

+64
-55
lines changed

6 files changed

+64
-55
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None,
11501150
def _bootstrap_median(data, N=5000):
11511151
# determine 95% confidence intervals of the median
11521152
M = len(data)
1153-
percentiles = [2.5, 97.5]
1153+
percentiles = (2.5, 97.5)
11541154

11551155
bs_index = np.random.randint(M, size=(N, M))
11561156
bsData = data[bs_index]
@@ -1169,8 +1169,9 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
11691169
else:
11701170

11711171
N = len(data)
1172-
notch_min = med - 1.57 * iqr / np.sqrt(N)
1173-
notch_max = med + 1.57 * iqr / np.sqrt(N)
1172+
half_height = 1.57 * iqr / (N ** (1 / 2))
1173+
notch_min = med - half_height
1174+
notch_max = med + half_height
11741175

11751176
return notch_min, notch_max
11761177

@@ -1221,7 +1222,8 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
12211222
stats['mean'] = np.mean(x)
12221223

12231224
# medians and quartiles
1224-
q1, med, q3 = np.percentile(x, [25, 50, 75])
1225+
percentiles = (25, 50, 75)
1226+
q1, med, q3 = np.percentile(x, percentiles)
12251227

12261228
# interquartile range
12271229
stats['iqr'] = q3 - q1

lib/matplotlib/markers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def _set_pentagon(self):
677677
self._path = polypath
678678
else:
679679
verts = polypath.vertices
680-
y = (1 + np.sqrt(5)) / 4.
680+
y = (1 + 5 ** (1 / 2)) / 4.
681681
top = Path(verts[[0, 1, 4, 0]])
682682
bottom = Path(verts[[1, 2, 3, 4, 1]])
683683
left = Path([verts[0], verts[1], verts[2], [0, -y], verts[0]])
@@ -747,7 +747,7 @@ def _set_hexagon2(self):
747747
else:
748748
verts = polypath.vertices
749749
# not drawing inside lines
750-
x, y = np.sqrt(3) / 4, 3 / 4.
750+
x, y = 3 ** (1 / 2) / 4, 3 / 4.
751751
top = Path(verts[[1, 0, 5, 4, 1]])
752752
bottom = Path(verts[1:5])
753753
left = Path(np.concatenate([
@@ -772,7 +772,7 @@ def _set_octagon(self):
772772
self._transform.rotate_deg(22.5)
773773
self._path = polypath
774774
else:
775-
x = np.sqrt(2.) / 4.
775+
x = 2 ** (1 / 2) / 4.
776776
self._path = self._alt_path = Path(
777777
[[0, -1], [0, 1], [-x, 1], [-1, x],
778778
[-1, -x], [-x, -1], [0, -1]])

lib/matplotlib/path.py

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -822,44 +822,48 @@ def circle(cls, center=(0., 0.), radius=1., readonly=False):
822822
Bezier Cubic Splines <https://www.tinaja.com/glib/ellipse4.pdf>`_.
823823
"""
824824
MAGIC = 0.2652031
825-
SQRTHALF = np.sqrt(0.5)
825+
SQRTHALF = (1 / 2) ** (1 / 2)
826826
MAGIC45 = SQRTHALF * MAGIC
827+
MAGICSUM = SQRTHALF + MAGIC45
828+
MAGICDIFF = SQRTHALF - MAGIC45
827829

828-
vertices = np.array([[0.0, -1.0],
830+
vertices = ((0.0, -1.0),
829831

830-
[MAGIC, -1.0],
831-
[SQRTHALF-MAGIC45, -SQRTHALF-MAGIC45],
832-
[SQRTHALF, -SQRTHALF],
832+
(MAGIC, -1.0),
833+
(MAGICDIFF, -MAGICSUM),
834+
(SQRTHALF, -SQRTHALF),
833835

834-
[SQRTHALF+MAGIC45, -SQRTHALF+MAGIC45],
835-
[1.0, -MAGIC],
836-
[1.0, 0.0],
836+
(MAGICSUM, -MAGICDIFF),
837+
(1.0, -MAGIC),
838+
(1.0, 0.0),
837839

838-
[1.0, MAGIC],
839-
[SQRTHALF+MAGIC45, SQRTHALF-MAGIC45],
840-
[SQRTHALF, SQRTHALF],
840+
(1.0, MAGIC),
841+
(MAGICSUM, MAGICDIFF),
842+
(SQRTHALF, SQRTHALF),
841843

842-
[SQRTHALF-MAGIC45, SQRTHALF+MAGIC45],
843-
[MAGIC, 1.0],
844-
[0.0, 1.0],
844+
(MAGICDIFF, MAGICSUM),
845+
(MAGIC, 1.0),
846+
(0.0, 1.0),
845847

846-
[-MAGIC, 1.0],
847-
[-SQRTHALF+MAGIC45, SQRTHALF+MAGIC45],
848-
[-SQRTHALF, SQRTHALF],
848+
(-MAGIC, 1.0),
849+
(-MAGICDIFF, MAGICSUM),
850+
(-SQRTHALF, SQRTHALF),
849851

850-
[-SQRTHALF-MAGIC45, SQRTHALF-MAGIC45],
851-
[-1.0, MAGIC],
852-
[-1.0, 0.0],
852+
(-MAGICSUM, MAGICDIFF),
853+
(-1.0, MAGIC),
854+
(-1.0, 0.0),
853855

854-
[-1.0, -MAGIC],
855-
[-SQRTHALF-MAGIC45, -SQRTHALF+MAGIC45],
856-
[-SQRTHALF, -SQRTHALF],
856+
(-1.0, -MAGIC),
857+
(-MAGICSUM, -MAGICDIFF),
858+
(-SQRTHALF, -SQRTHALF),
857859

858-
[-SQRTHALF+MAGIC45, -SQRTHALF-MAGIC45],
859-
[-MAGIC, -1.0],
860-
[0.0, -1.0],
860+
(-MAGICDIFF, -MAGICSUM),
861+
(-MAGIC, -1.0),
862+
(0.0, -1.0),
861863

862-
[0.0, -1.0]],
864+
(0.0, -1.0))
865+
866+
vertices = np.array(vertices,
863867
dtype=float)
864868

865869
codes = [cls.CURVE4] * 26
@@ -878,31 +882,34 @@ def unit_circle_righthalf(cls):
878882
"""
879883
if cls._unit_circle_righthalf is None:
880884
MAGIC = 0.2652031
881-
SQRTHALF = np.sqrt(0.5)
885+
SQRTHALF = (1 / 2) ** (1 / 2)
882886
MAGIC45 = SQRTHALF * MAGIC
887+
MAGICSUM = SQRTHALF + MAGIC45
888+
MAGICDIFF = SQRTHALF - MAGIC45
889+
883890

884-
vertices = np.array(
885-
[[0.0, -1.0],
891+
vertices = ((0.0, -1.0),
886892

887-
[MAGIC, -1.0],
888-
[SQRTHALF-MAGIC45, -SQRTHALF-MAGIC45],
889-
[SQRTHALF, -SQRTHALF],
893+
(MAGIC, -1.0),
894+
(MAGICDIFF, -MAGICSUM),
895+
(SQRTHALF, -SQRTHALF),
890896

891-
[SQRTHALF+MAGIC45, -SQRTHALF+MAGIC45],
892-
[1.0, -MAGIC],
893-
[1.0, 0.0],
897+
(MAGICSUM, -MAGICDIFF),
898+
(1.0, -MAGIC),
899+
(1.0, 0.0),
894900

895-
[1.0, MAGIC],
896-
[SQRTHALF+MAGIC45, SQRTHALF-MAGIC45],
897-
[SQRTHALF, SQRTHALF],
901+
(1.0, MAGIC),
902+
(MAGICSUM, MAGICDIFF),
903+
(SQRTHALF, SQRTHALF),
898904

899-
[SQRTHALF-MAGIC45, SQRTHALF+MAGIC45],
900-
[MAGIC, 1.0],
901-
[0.0, 1.0],
905+
(MAGICDIFF, MAGICSUM),
906+
(MAGIC, 1.0),
907+
(0.0, 1.0),
902908

903-
[0.0, -1.0]],
909+
(0.0, -1.0))
904910

905-
float)
911+
vertices = np.array(vertices,
912+
dtype=float)
906913

907914
codes = np.full(14, cls.CURVE4, dtype=cls.code_type)
908915
codes[0] = cls.MOVETO

lib/matplotlib/patheffects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def __init__(self, offset=(0, 0),
411411
to your right, and 180 behind you.
412412
length : float, default: 1.414
413413
The length of the tick relative to spacing.
414-
Recommended length = 1.414 (sqrt(2)) when angle=45, length=1.0
414+
Recommended length = 1.414 (:math:`\\sqrt{2}`) when angle=45, length=1.0
415415
when angle=90 and length=2.0 when angle=60.
416416
**kwargs
417417
Extra keywords are stored and passed through to

lib/matplotlib/projections/polar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def transform_non_affine(self, xy):
165165
# docstring inherited
166166
x, y = xy.T
167167
r = np.hypot(x, y)
168-
theta = (np.arctan2(y, x) + 2 * np.pi) % (2 * np.pi)
168+
theta = np.arctan2(y, x) % (2 * np.pi)
169169
# PolarAxes does not use the theta transforms here, but apply them for
170170
# backwards-compatibility if not being used by it.
171171
if self._apply_theta_transforms and self._axis is not None:
@@ -1076,7 +1076,7 @@ def set_theta_zero_location(self, loc, offset=0.0):
10761076
'SW': np.pi * 1.25,
10771077
'S': np.pi * 1.5,
10781078
'SE': np.pi * 1.75,
1079-
'E': 0,
1079+
'E': 0.,
10801080
'NE': np.pi * 0.25}
10811081
return self.set_theta_offset(mapping[loc] + np.deg2rad(offset))
10821082

lib/matplotlib/streamplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def _get_integrator(u, v, dmap, minlength, maxlength, integration_direction):
440440
# speed (path length) will be in axes-coordinates
441441
u_ax = u / (dmap.grid.nx - 1)
442442
v_ax = v / (dmap.grid.ny - 1)
443-
speed = np.ma.sqrt(u_ax ** 2 + v_ax ** 2)
443+
speed = np.ma.hypot(u_ax, v_ax)
444444

445445
def forward_time(xi, yi):
446446
if not dmap.grid.within_grid(xi, yi):

0 commit comments

Comments
 (0)