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

Skip to content

Commit 654a98c

Browse files
committed
clip and ptp are awesome.
1 parent 90ded74 commit 654a98c

5 files changed

Lines changed: 15 additions & 18 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3397,10 +3397,11 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
33973397
Sets the positions of the boxes. The ticks and limits
33983398
are automatically set to match the positions.
33993399
3400-
widths : array-like, default = 0.5
3400+
widths : array-like, default = None
34013401
Either a scalar or a vector and sets the width of each
3402-
box. The default is 0.5, or ``0.15*(distance between extreme
3403-
positions)`` if that is smaller.
3402+
box. The default is ``0.15*(distance between extreme
3403+
positions)``, clipped to no less than 0.15 and no more than
3404+
0.5.
34043405
34053406
vert : bool, default = False
34063407
If `True` (default), makes the boxes vertical. If `False`,
@@ -3637,8 +3638,7 @@ def dopatch(xs, ys, **kwargs):
36373638

36383639
# width
36393640
if widths is None:
3640-
distance = max(positions) - min(positions)
3641-
widths = [min(0.15 * max(distance, 1.0), 0.5)] * N
3641+
widths = [np.clip(0.15 * np.ptp(positions), 0.15, 0.5)] * N
36423642
elif np.isscalar(widths):
36433643
widths = [widths] * N
36443644
elif len(widths) != N:

lib/matplotlib/quiver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ def _init(self):
523523
(ax.bbox.width, ax.bbox.height))
524524
self.span = sx
525525
if self.width is None:
526-
sn = max(8, min(25, math.sqrt(self.N)))
526+
sn = np.clip(math.sqrt(self.N), 8, 25)
527527
self.width = 0.06 * self.span / sn
528528

529529
# _make_verts sets self.scale if not already specified

lib/matplotlib/ticker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,8 +1875,8 @@ def set_params(self, **kwargs):
18751875
def _raw_ticks(self, vmin, vmax):
18761876
if self._nbins == 'auto':
18771877
if self.axis is not None:
1878-
nbins = max(min(self.axis.get_tick_space(), 9),
1879-
max(1, self._min_n_ticks - 1))
1878+
nbins = np.clip(self.axis.get_tick_space(),
1879+
max(1, self._min_n_ticks - 1), 9)
18801880
else:
18811881
nbins = 9
18821882
else:
@@ -2074,7 +2074,7 @@ def __call__(self):
20742074
def tick_values(self, vmin, vmax):
20752075
if self.numticks == 'auto':
20762076
if self.axis is not None:
2077-
numticks = max(min(self.axis.get_tick_space(), 9), 2)
2077+
numticks = np.clip(self.axis.get_tick_space(), 2, 9)
20782078
else:
20792079
numticks = 9
20802080
else:

lib/matplotlib/tri/triinterpolate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,10 @@ def __init__(self, triangulation, z, kind='min_E', trifinder=None,
417417
self._z = self._z[~node_mask]
418418

419419
# Computing scale factors
420-
self._unit_x = np.max(compressed_x) - np.min(compressed_x)
421-
self._unit_y = np.max(compressed_y) - np.min(compressed_y)
422-
self._pts = np.vstack((compressed_x/float(self._unit_x),
423-
compressed_y/float(self._unit_y))).T
420+
self._unit_x = np.ptp(compressed_x)
421+
self._unit_y = np.ptp(compressed_y)
422+
self._pts = np.column_stack([compressed_x / self._unit_x,
423+
compressed_y / self._unit_y])
424424
# Computing triangle points
425425
self._tris_pts = self._pts[self._triangles]
426426
# Computing eccentricities

lib/matplotlib/tri/tritools.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ def scale_factors(self):
5050
compressed_triangles = self._triangulation.get_masked_triangles()
5151
node_used = (np.bincount(np.ravel(compressed_triangles),
5252
minlength=self._triangulation.x.size) != 0)
53-
x = self._triangulation.x[node_used]
54-
y = self._triangulation.y[node_used]
55-
ux = np.max(x)-np.min(x)
56-
uy = np.max(y)-np.min(y)
57-
return (1./float(ux), 1./float(uy))
53+
return (1 / np.ptp(self._triangulation.x[node_used]),
54+
1 / np.ptp(self._triangulation.y[node_used]))
5855

5956
def circle_ratios(self, rescale=True):
6057
"""

0 commit comments

Comments
 (0)