def _set_transform(self): self.set_transform(cbook._check_getitem({ "data": self.Q.axes.transData, "axes": self.Q.axes.transAxes, "figure": self.Q.axes.figure.transFigure, "inches": self.Q.axes.figure.dpi_scale_trans, }, coordinates=self.coord))
def __init__(self, base, nonpositive='clip'): Transform.__init__(self) if base <= 0 or base == 1: raise ValueError('The log base cannot be <= 0 or == 1') self.base = base self._clip = cbook._check_getitem( {"clip": True, "mask": False}, nonpositive=nonpositive)
def finalize_offset(self): update_method = cbook._check_getitem( { "loc": self._update_loc, "bbox": self._bbox_to_anchor }, update=self._update) update_method(self.get_loc_in_canvas())
def set_axislabel_direction(self, label_direction): r""" Adjust the direction of the axislabel. Note that the *label_direction*\s '+' and '-' are relative to the direction of the increasing coordinate. Parameters ---------- tick_direction : {"+", "-"} """ self._axislabel_add_angle = cbook._check_getitem( {"+": 0, "-": 180}, label_direction=label_direction)
def _print_ps(self, outfile, format, *args, dpi=72, metadata=None, papertype=None, orientation='portrait', **kwargs): self.figure.set_dpi(72) # Override the dpi kwarg dsc_comments = {} if isinstance(outfile, (str, os.PathLike)): dsc_comments["Title"] = \ os.fspath(outfile).encode("ascii", "replace").decode("ascii") dsc_comments["Creator"] = (metadata or {}).get( "Creator", f"matplotlib version {mpl.__version__}, http://matplotlib.org/") # See https://reproducible-builds.org/specs/source-date-epoch/ source_date_epoch = os.getenv("SOURCE_DATE_EPOCH") dsc_comments["CreationDate"] = (datetime.datetime.utcfromtimestamp( int(source_date_epoch)).strftime("%a %b %d %H:%M:%S %Y") if source_date_epoch else time.ctime()) dsc_comments = "\n".join(f"%%{k}: {v}" for k, v in dsc_comments.items()) if papertype is None: papertype = mpl.rcParams['ps.papersize'] papertype = papertype.lower() cbook._check_in_list(['auto', *papersize], papertype=papertype) orientation = cbook._check_getitem(_Orientation, orientation=orientation.lower()) printer = (self._print_figure_tex if mpl.rcParams['text.usetex'] else self._print_figure) printer(outfile, format, dpi=dpi, dsc_comments=dsc_comments, orientation=orientation, papertype=papertype, **kwargs)
def _print_ps(self, outfile, format, *args, papertype=None, dpi=72, facecolor='w', edgecolor='w', orientation='portrait', **kwargs): if papertype is None: papertype = mpl.rcParams['ps.papersize'] papertype = papertype.lower() cbook._check_in_list(['auto', *papersize], papertype=papertype) orientation = cbook._check_getitem( _Orientation, orientation=orientation.lower()) self.figure.set_dpi(72) # Override the dpi kwarg printer = (self._print_figure_tex if mpl.rcParams['text.usetex'] else self._print_figure) printer(outfile, format, dpi, facecolor, edgecolor, orientation, papertype, **kwargs)
def __init__(self, value, units): """Create a new UnitDbl object. Units are internally converted to km, rad, and sec. The only valid inputs for units are [m, km, mile, rad, deg, sec, min, hour]. The field UnitDbl.value will contain the converted value. Use the convert() method to get a specific type of units back. = ERROR CONDITIONS - If the input units are not in the allowed list, an error is thrown. = INPUT VARIABLES - value The numeric value of the UnitDbl. - units The string name of the units the value is in. """ data = cbook._check_getitem(self.allowed, units=units) self._value = float(value * data[0]) self._units = data[1]
def _parse_cached(self, s, dpi, prop, force_standard_ps_fonts): if prop is None: prop = FontProperties() fontset_class = (_mathtext.StandardPsFonts if force_standard_ps_fonts else cbook._check_getitem( self._font_type_mapping, fontset=prop.get_math_fontfamily())) backend = self._backend_mapping[self._output]() font_output = fontset_class(prop, backend) fontsize = prop.get_size_in_points() # This is a class variable so we don't rebuild the parser # with each request. if self._parser is None: self.__class__._parser = _mathtext.Parser() box = self._parser.parse(s, font_output, fontsize, dpi) font_output.set_canvas_size(box.width, box.height, box.depth) return font_output.get_results(box)
def convert(self, units): """Convert the UnitDbl to a specific set of units. = ERROR CONDITIONS - If the input units are not in the allowed list, an error is thrown. = INPUT VARIABLES - units The string name of the units to convert to. = RETURN VALUE - Returns the value of the UnitDbl in the requested units as a floating point number. """ if self._units == units: return self._value data = cbook._check_getitem(self.allowed, units=units) if self._units != data[1]: raise ValueError(f"Error trying to convert to different units.\n" f" Invalid conversion requested.\n" f" UnitDbl: {self}\n" f" Units: {units}\n") return self._value / data[0]
def set_default_angle(self, d): self.set_rotation(cbook._check_getitem(self._default_angles, d=d))
def set_default_alignment(self, d): va, ha = cbook._check_getitem(self._default_alignments, d=d) self.set_va(va) self.set_ha(ha)