|
6 | 6 |
|
7 | 7 | import re
|
8 | 8 | import numpy as np
|
9 |
| -from numpy import ma |
10 | 9 |
|
11 | 10 | import matplotlib as mpl
|
12 | 11 | import matplotlib.category # Register category unit converter as side effect.
|
@@ -5551,143 +5550,58 @@ def _fill_between_x_or_y(
|
5551 | 5550 | i.e. constant in between *{ind}*. The value determines where the
|
5552 | 5551 | step will occur:
|
5553 | 5552 |
|
5554 |
| - - 'pre': The y value is continued constantly to the left from |
5555 |
| - every *x* position, i.e. the interval ``(x[i-1], x[i]]`` has the |
5556 |
| - value ``y[i]``. |
| 5553 | + - 'pre': The {dep} value is continued constantly to the left from |
| 5554 | + every *{ind}* position, i.e. the interval ``({ind}[i-1], {ind}[i]]`` |
| 5555 | + has the value ``{dep}[i]``. |
5557 | 5556 | - 'post': The y value is continued constantly to the right from
|
5558 |
| - every *x* position, i.e. the interval ``[x[i], x[i+1])`` has the |
5559 |
| - value ``y[i]``. |
5560 |
| - - 'mid': Steps occur half-way between the *x* positions. |
| 5557 | + every *{ind}* position, i.e. the interval ``[{ind}[i], {ind}[i+1])`` |
| 5558 | + has the value ``{dep}[i]``. |
| 5559 | + - 'mid': Steps occur half-way between the *{ind}* positions. |
5561 | 5560 |
|
5562 | 5561 | Returns
|
5563 | 5562 | -------
|
5564 |
| - `.PolyCollection` |
5565 |
| - A `.PolyCollection` containing the plotted polygons. |
| 5563 | + `.FillBetweenPolyCollection` |
| 5564 | + A `.FillBetweenPolyCollection` containing the plotted polygons. |
5566 | 5565 |
|
5567 | 5566 | Other Parameters
|
5568 | 5567 | ----------------
|
5569 | 5568 | data : indexable object, optional
|
5570 | 5569 | DATA_PARAMETER_PLACEHOLDER
|
5571 | 5570 |
|
5572 | 5571 | **kwargs
|
5573 |
| - All other keyword arguments are passed on to `.PolyCollection`. |
5574 |
| - They control the `.Polygon` properties: |
| 5572 | + All other keyword arguments are passed on to |
| 5573 | + `.FillBetweenPolyCollection`. They control the `.Polygon` properties: |
5575 | 5574 |
|
5576 |
| - %(PolyCollection:kwdoc)s |
| 5575 | + %(FillBetweenPolyCollection:kwdoc)s |
5577 | 5576 |
|
5578 | 5577 | See Also
|
5579 | 5578 | --------
|
5580 | 5579 | fill_between : Fill between two sets of y-values.
|
5581 | 5580 | fill_betweenx : Fill between two sets of x-values.
|
5582 | 5581 | """
|
5583 |
| - |
5584 |
| - dep_dir = {"x": "y", "y": "x"}[ind_dir] |
| 5582 | + dep_dir = mcoll.FillBetweenPolyCollection._f_dir_from_t(ind_dir) |
5585 | 5583 |
|
5586 | 5584 | if not mpl.rcParams["_internal.classic_mode"]:
|
5587 | 5585 | kwargs = cbook.normalize_kwargs(kwargs, mcoll.Collection)
|
5588 | 5586 | if not any(c in kwargs for c in ("color", "facecolor")):
|
5589 |
| - kwargs["facecolor"] = \ |
5590 |
| - self._get_patches_for_fill.get_next_color() |
5591 |
| - |
5592 |
| - # Handle united data, such as dates |
5593 |
| - ind, dep1, dep2 = map( |
5594 |
| - ma.masked_invalid, self._process_unit_info( |
5595 |
| - [(ind_dir, ind), (dep_dir, dep1), (dep_dir, dep2)], kwargs)) |
5596 |
| - |
5597 |
| - for name, array in [ |
5598 |
| - (ind_dir, ind), (f"{dep_dir}1", dep1), (f"{dep_dir}2", dep2)]: |
5599 |
| - if array.ndim > 1: |
5600 |
| - raise ValueError(f"{name!r} is not 1-dimensional") |
| 5587 | + kwargs["facecolor"] = self._get_patches_for_fill.get_next_color() |
5601 | 5588 |
|
5602 |
| - if where is None: |
5603 |
| - where = True |
5604 |
| - else: |
5605 |
| - where = np.asarray(where, dtype=bool) |
5606 |
| - if where.size != ind.size: |
5607 |
| - raise ValueError(f"where size ({where.size}) does not match " |
5608 |
| - f"{ind_dir} size ({ind.size})") |
5609 |
| - where = where & ~functools.reduce( |
5610 |
| - np.logical_or, map(np.ma.getmaskarray, [ind, dep1, dep2])) |
5611 |
| - |
5612 |
| - ind, dep1, dep2 = np.broadcast_arrays( |
5613 |
| - np.atleast_1d(ind), dep1, dep2, subok=True) |
5614 |
| - |
5615 |
| - polys = [] |
5616 |
| - for idx0, idx1 in cbook.contiguous_regions(where): |
5617 |
| - indslice = ind[idx0:idx1] |
5618 |
| - dep1slice = dep1[idx0:idx1] |
5619 |
| - dep2slice = dep2[idx0:idx1] |
5620 |
| - if step is not None: |
5621 |
| - step_func = cbook.STEP_LOOKUP_MAP["steps-" + step] |
5622 |
| - indslice, dep1slice, dep2slice = \ |
5623 |
| - step_func(indslice, dep1slice, dep2slice) |
5624 |
| - |
5625 |
| - if not len(indslice): |
5626 |
| - continue |
| 5589 | + ind, dep1, dep2 = self._fill_between_process_units( |
| 5590 | + ind_dir, dep_dir, ind, dep1, dep2, **kwargs) |
5627 | 5591 |
|
5628 |
| - N = len(indslice) |
5629 |
| - pts = np.zeros((2 * N + 2, 2)) |
5630 |
| - |
5631 |
| - if interpolate: |
5632 |
| - def get_interp_point(idx): |
5633 |
| - im1 = max(idx - 1, 0) |
5634 |
| - ind_values = ind[im1:idx+1] |
5635 |
| - diff_values = dep1[im1:idx+1] - dep2[im1:idx+1] |
5636 |
| - dep1_values = dep1[im1:idx+1] |
5637 |
| - |
5638 |
| - if len(diff_values) == 2: |
5639 |
| - if np.ma.is_masked(diff_values[1]): |
5640 |
| - return ind[im1], dep1[im1] |
5641 |
| - elif np.ma.is_masked(diff_values[0]): |
5642 |
| - return ind[idx], dep1[idx] |
5643 |
| - |
5644 |
| - diff_order = diff_values.argsort() |
5645 |
| - diff_root_ind = np.interp( |
5646 |
| - 0, diff_values[diff_order], ind_values[diff_order]) |
5647 |
| - ind_order = ind_values.argsort() |
5648 |
| - diff_root_dep = np.interp( |
5649 |
| - diff_root_ind, |
5650 |
| - ind_values[ind_order], dep1_values[ind_order]) |
5651 |
| - return diff_root_ind, diff_root_dep |
5652 |
| - |
5653 |
| - start = get_interp_point(idx0) |
5654 |
| - end = get_interp_point(idx1) |
5655 |
| - else: |
5656 |
| - # Handle scalar dep2 (e.g. 0): the fill should go all |
5657 |
| - # the way down to 0 even if none of the dep1 sample points do. |
5658 |
| - start = indslice[0], dep2slice[0] |
5659 |
| - end = indslice[-1], dep2slice[-1] |
5660 |
| - |
5661 |
| - pts[0] = start |
5662 |
| - pts[N + 1] = end |
5663 |
| - |
5664 |
| - pts[1:N+1, 0] = indslice |
5665 |
| - pts[1:N+1, 1] = dep1slice |
5666 |
| - pts[N+2:, 0] = indslice[::-1] |
5667 |
| - pts[N+2:, 1] = dep2slice[::-1] |
5668 |
| - |
5669 |
| - if ind_dir == "y": |
5670 |
| - pts = pts[:, ::-1] |
5671 |
| - |
5672 |
| - polys.append(pts) |
5673 |
| - |
5674 |
| - collection = mcoll.PolyCollection(polys, **kwargs) |
5675 |
| - |
5676 |
| - # now update the datalim and autoscale |
5677 |
| - pts = np.vstack([np.hstack([ind[where, None], dep1[where, None]]), |
5678 |
| - np.hstack([ind[where, None], dep2[where, None]])]) |
5679 |
| - if ind_dir == "y": |
5680 |
| - pts = pts[:, ::-1] |
5681 |
| - |
5682 |
| - up_x = up_y = True |
5683 |
| - if "transform" in kwargs: |
5684 |
| - up_x, up_y = kwargs["transform"].contains_branch_seperately(self.transData) |
5685 |
| - self.update_datalim(pts, updatex=up_x, updatey=up_y) |
| 5592 | + collection = mcoll.FillBetweenPolyCollection( |
| 5593 | + ind_dir, ind, dep1, dep2, |
| 5594 | + where=where, interpolate=interpolate, step=step, **kwargs) |
5686 | 5595 |
|
5687 |
| - self.add_collection(collection, autolim=False) |
| 5596 | + self.add_collection(collection) |
5688 | 5597 | self._request_autoscale_view()
|
5689 | 5598 | return collection
|
5690 | 5599 |
|
| 5600 | + def _fill_between_process_units(self, ind_dir, dep_dir, ind, dep1, dep2, **kwargs): |
| 5601 | + """Handle united data, such as dates.""" |
| 5602 | + return map(np.ma.masked_invalid, self._process_unit_info( |
| 5603 | + [(ind_dir, ind), (dep_dir, dep1), (dep_dir, dep2)], kwargs)) |
| 5604 | + |
5691 | 5605 | def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
|
5692 | 5606 | step=None, **kwargs):
|
5693 | 5607 | return self._fill_between_x_or_y(
|
|
0 commit comments