8000 clip and ptp are awesome. · matplotlib/matplotlib@5b1f777 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5b1f777

Browse files
committed
clip and ptp are awesome.
1 parent 9d802a9 commit 5b1f777

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3450,10 +3450,11 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
34503450
Sets the positions of the boxes. The ticks and limits
34513451
are automatically set to match the positions.
34523452
3453-
widths : array-like, default = 0.5
3453+
widths : array-like, default = None
34543454
Either a scalar or a vector and sets the width of each
3455-
box. The default is 0.5, or ``0.15*(distance between extreme
3456-
positions)`` if that is smaller.
3455+
box. The default is ``0.15*(distance between extreme
3456+
positions)``, clipped to no less than 0.15 and no more than
3457+
0.5.
34573458
34583459
vert : bool, default = False
34593460
If `True` (default), makes the boxes vertical. If `False`,
@@ -3690,8 +3691,7 @@ def dopatch(xs, ys, **kwargs):
36903691

36913692
# width
36923693
if widths is None:
3693-
distance = max(positions) - min(positions)
3694-
widths = [min(0.15 * max(distance, 1.0), 0.5)] * N
3694+
widths = [np.clip(0.15 * np.ptp(positions), 0.15, 0.5)] * N
36953695
elif np.isscalar(widths):
36963696
widths = [widths] * N
36973697
elif len(widths) != N:

lib/matplotlib/quiver.py

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

533533
# _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
@@ -1873,8 +1873,8 @@ def set_params(self, **kwargs):
18731873
def _raw_ticks(self, vmin, vmax):
18741874
if self._nbins == 'auto':
18751875
if self.axis is not None:
1876-
nbins = max(min(self.axis.get_tick_space(), 9),
1877-
max(1, self._min_n_ticks - 1))
1876+
nbins = np.clip(self.axis.get_tick_space(),
1877+
max(1, self._min_n_ticks - 1), 9)
18781878
else:
18791879
nbins = 9
18801880
else:
@@ -2072,7 +2072,7 @@ def __call__(self):
20722072
def tick_values(self, vmin, vmax):
20732073
if self.numticks == 'auto':
20742074
if self.axis is not None:
2075-
numticks = max(min(self.axis.get_tick_space(), 9), 2)
2075+
numticks = np.clip(self.axis.get_tick_space(), 2, 9)
20762076
else:
20772077
numticks = 9
20782078
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)
0