def get_edgecolor(self): # We need this check here to make sure we do not double-apply the depth # based alpha shading when the edge color is "face" which means the # edge colour should be identical to the face colour. if cbook._str_equal(self._edgecolors, 'face'): return self.get_facecolor() return self._maybe_depth_shade_and_sort_colors(super().get_edgecolor())
def set_color(self, color): # docstring inherited # Unlike the base Line2D.set_color, this also supports "auto". if not cbook._str_equal(color, "auto"): mcolors._check_color_like(color=color) self._color = color self.stale = True
def _validate_color_or_linecolor(s): if cbook._str_equal(s, 'linecolor'): return s elif cbook._str_equal(s, 'mfc') or cbook._str_equal(s, 'markerfacecolor'): return 'markerfacecolor' elif cbook._str_equal(s, 'mec') or cbook._str_equal(s, 'markeredgecolor'): return 'markeredgecolor' elif s is None: return None elif isinstance(s, str) and len(s) == 6 or len(s) == 8: stmp = '#' + s if is_color_like(stmp): return stmp if s.lower() == 'none': return None elif is_color_like(s): return s raise ValueError(f'{s!r} does not look like a color arg')
def __init__(self, dataset, bw_method=None): self.dataset = np.atleast_2d(dataset) if not np.array(self.dataset).size > 1: raise ValueError("`dataset` input should have multiple elements.") self.dim, self.num_dp = np.array(self.dataset).shape if bw_method is None: pass elif cbook._str_equal(bw_method, 'scott'): self.covariance_factor = self.scotts_factor elif cbook._str_equal(bw_method, 'silverman'): self.covariance_factor = self.silverman_factor elif isinstance(bw_method, Number): self._bw_method = 'use constant' self.covariance_factor = lambda: bw_method elif callable(bw_method): self._bw_method = bw_method self.covariance_factor = lambda: self._bw_method(self) else: raise ValueError("`bw_method` should be 'scott', 'silverman', a " "scalar or a callable") # Computes the covariance matrix for each Gaussian kernel using # covariance_factor(). self.factor = self.covariance_factor() # Cache covariance and inverse covariance of the data if not hasattr(self, '_data_inv_cov'): self.data_covariance = np.atleast_2d( np.cov( self.dataset, rowvar=1, bias=False)) self.data_inv_cov = np.linalg.inv(self.data_covariance) self.covariance = self.data_covariance * self.factor ** 2 self.inv_cov = self.data_inv_cov / self.factor ** 2 self.norm_factor = np.sqrt( np.linalg.det( 2 * np.pi * self.covariance)) * self.num_dp
def __init__(self, dataset, bw_method=None): self.dataset = np.atleast_2d(dataset) if not np.array(self.dataset).size > 1: raise ValueError("`dataset` input should have multiple elements.") self.dim, self.num_dp = np.array(self.dataset).shape if bw_method is None: pass elif cbook._str_equal(bw_method, 'scott'): self.covariance_factor = self.scotts_factor elif cbook._str_equal(bw_method, 'silverman'): self.covariance_factor = self.silverman_factor elif isinstance(bw_method, Number): self._bw_method = 'use constant' self.covariance_factor = lambda: bw_method elif callable(bw_method): self._bw_method = bw_method self.covariance_factor = lambda: self._bw_method(self) else: raise ValueError("`bw_method` should be 'scott', 'silverman', a " "scalar or a callable") # Computes the covariance matrix for each Gaussian kernel using # covariance_factor(). self.factor = self.covariance_factor() # Cache covariance and inverse covariance of the data if not hasattr(self, '_data_inv_cov'): self.data_covariance = np.atleast_2d( np.cov( self.dataset, rowvar=1, bias=False)) self.data_inv_cov = np.linalg.inv(self.data_covariance) self.covariance = self.data_covariance * self.factor ** 2 self.inv_cov = self.data_inv_cov / self.factor ** 2 self.norm_factor = (np.sqrt(np.linalg.det(2 * np.pi * self.covariance)) * self.num_dp)
def score_weight(self, weight1, weight2): """ Return a match score between *weight1* and *weight2*. The result is 0.0 if both weight1 and weight 2 are given as strings and have the same value. Otherwise, the result is the absolute value of the difference between the CSS numeric values of *weight1* and *weight2*, normalized between 0.05 and 1.0. """ # exact match of the weight names, e.g. weight1 == weight2 == "regular" if cbook._str_equal(weight1, weight2): return 0.0 w1 = weight1 if isinstance(weight1, Number) else weight_dict[weight1] w2 = weight2 if isinstance(weight2, Number) else weight_dict[weight2] return 0.95 * (abs(w1 - w2) / 1000) + 0.05
def score_weight(self, weight1, weight2): """ Returns a match score between *weight1* and *weight2*. The result is 0.0 if both weight1 and weight 2 are given as strings and have the same value. Otherwise, the result is the absolute value of the difference between the CSS numeric values of *weight1* and *weight2*, normalized between 0.05 and 1.0. """ # exact match of the weight names, e.g. weight1 == weight2 == "regular" if cbook._str_equal(weight1, weight2): return 0.0 w1 = weight1 if isinstance(weight1, Number) else weight_dict[weight1] w2 = weight2 if isinstance(weight2, Number) else weight_dict[weight2] return 0.95 * (abs(w1 - w2) / 1000) + 0.05
def validate_color_or_auto(s): if cbook._str_equal(s, 'auto'): return s return validate_color(s)
def validate_color_or_inherit(s): """Return a valid color arg.""" if cbook._str_equal(s, 'inherit'): return s return validate_color(s)