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

Skip to content

Commit 467683d

Browse files
committed
feat: histline color handling
1 parent 157aecf commit 467683d

File tree

4 files changed

+36
-46
lines changed

4 files changed

+36
-46
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6874,8 +6874,12 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
68746874
def histline(self, vals, bins=None, *,
68756875
orientation='horizontal', baseline=0, fill=False, **kwargs):
68766876

6877-
if 'color' not in kwargs:
6878-
kwargs['color'] = self._get_lines.get_next_color()
6877+
_color = self._get_lines.get_next_color()
6878+
if not fill:
6879+
kwargs.setdefault('edgecolor', _color)
6880+
else:
6881+
kwargs.setdefault('edgecolor', 'none')
6882+
kwargs.setdefault('facecolor', _color)
68796883

68806884
if bins is None:
68816885
bins = np.arange(len(vals)+1)

lib/matplotlib/legend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
from matplotlib.cbook import silent_list
3434
from matplotlib.font_manager import FontProperties
3535
from matplotlib.lines import Line2D
36-
from matplotlib.patches import Patch, Rectangle, Shadow, FancyBboxPatch, StepPatch
36+
from matplotlib.patches import (Patch, Rectangle, Shadow, FancyBboxPatch,
37+
StepPatch)
3738
from matplotlib.collections import (LineCollection, RegularPolyCollection,
3839
CircleCollection, PathCollection,
3940
PolyCollection)

lib/matplotlib/legend_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ def patch_func(legend=legend, orig_handle=orig_handle,
331331
def _create_patch(self, legend, orig_handle,
332332
xdescent, ydescent, width, height, fontsize):
333333
if self._patch_func is None:
334-
p = Rectangle(xy=(-xdescent, -ydescent), color=orig_handle.get_facecolor(),
334+
p = Rectangle(xy=(-xdescent, -ydescent),
335+
color=orig_handle.get_facecolor(),
335336
width=width, height=height)
336337
else:
337338
p = self._patch_func(legend=legend, orig_handle=orig_handle,

lib/matplotlib/patches.py

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,32 @@ def set_path(self, path):
990990

991991

992992
class StepPatch(PathPatch):
993+
"""A stepline path patch."""
994+
995+
@docstring.dedent_interpd
993996
def __init__(self, vals, bins=None, *,
994997
orientation='horizontal', baseline=0, **kwargs):
998+
"""
999+
Parameters
1000+
----------
1001+
vals : array, len N
1002+
An array of y-values.
1003+
1004+
bins : array, len N+1
1005+
A array of x-values, between which the curve takes on
1006+
vals values.
1007+
1008+
orientation : {'vertical', 'horizontal'}, default: 'vertical'
1009+
1010+
baseline : float or None, default: 0
1011+
Determines starting value of the bounding edges or when
1012+
"fill" == True, position of lower edge.
1013+
1014+
**kwargs
1015+
`Patch` properties:
1016+
1017+
%(Patch)s
1018+
"""
9951019
self.baseline = baseline
9961020
self.orientation = orientation
9971021
self._bins = bins
@@ -1005,9 +1029,9 @@ def _update_data(self):
10051029
raise ValueError('the length of the bins is wrong')
10061030
verts, codes = [], []
10071031
for idx0, idx1 in cbook.contiguous_regions(~np.isnan(self._vals)):
1008-
x = np.vstack((self._bins[idx0:idx1+1],
1032+
x = np.vstack((self._bins[idx0:idx1+1],
10091033
self._bins[idx0:idx1+1])).T.flatten()
1010-
y = np.vstack((self._vals[idx0:idx1],
1034+
y = np.vstack((self._vals[idx0:idx1],
10111035
self._vals[idx0:idx1])).T.flatten()
10121036
if self.baseline is not None:
10131037
y = np.hstack((self.baseline, y, self.baseline))
@@ -1129,46 +1153,6 @@ def set_xy(self, xy):
11291153
doc='The vertices of the path as (N, 2) numpy array.')
11301154

11311155

1132-
class HistLine(Polygon):
1133-
1134-
def __init__(self, vals, bins=None, *, fill=False,
1135-
orientation='horizontal', baseline=0, **kwargs):
1136-
self.baseline = baseline
1137-
self.orientation = orientation
1138-
self._color = None
1139-
self._bins = bins
1140-
self._vals = vals
1141-
xy = self._update_data()
1142-
super(HistLine, self).__init__(xy, closed=False, fill=fill, **kwargs)
1143-
1144-
def _update_data(self):
1145-
if self._bins.size - 1 != self._vals.size:
1146-
raise ValueError('the length of the bins is wrong')
1147-
x = np.vstack((self._bins, self._bins)).T.flatten()
1148-
y = np.vstack((self._vals, self._vals)).T.flatten()
1149-
if self.baseline is not None:
1150-
y = np.hstack((self.baseline, y, self.baseline))
1151-
else:
1152-
y = np.hstack((y[0], y, y[-1]))
1153-
if self.orientation == 'horizontal':
1154-
return np.vstack([x, y]).T
1155-
else:
1156-
return np.vstack([y, x]).T
1157-
1158-
def set_bins(self, bins):
1159-
self._bins = bins
1160-
self._update_data()
1161-
1162-
def set_vals(self, vals):
1163-
self._vals = vals
1164-
self._update_data()
1165-
1166-
def set_vals_bins(self, vals, bins):
1167-
self._vals = vals
1168-
self._bins = bins
1169-
self._update_data()
1170-
1171-
11721156
class Wedge(Patch):
11731157
"""Wedge shaped patch."""
11741158

0 commit comments

Comments
 (0)