本文整理汇总了Python中matplotlib.ticker.Formatter方法的典型用法代码示例。如果您正苦于以下问题:Python ticker.Formatter方法的具体用法?Python ticker.Formatter怎么用?Python ticker.Formatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.ticker
的用法示例。
在下文中一共展示了ticker.Formatter方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: autoscale
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import Formatter [as 别名]
def autoscale(self):
"""
Sets the view limits to the nearest multiples of base that contain the
data.
"""
# requires matplotlib >= 0.98.0
(vmin, vmax) = self.axis.get_data_interval()
locs = self._get_default_locs(vmin, vmax)
(vmin, vmax) = locs[[0, -1]]
if vmin == vmax:
vmin -= 1
vmax += 1
return nonsingular(vmin, vmax)
# -------------------------------------------------------------------------
# --- Formatter ---
# -------------------------------------------------------------------------
示例2: autoscale
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import Formatter [as 别名]
def autoscale(self):
"""
Sets the view limits to the nearest multiples of base that contain the
data.
"""
# requires matplotlib >= 0.98.0
(vmin, vmax) = self.axis.get_data_interval()
locs = self._get_default_locs(vmin, vmax)
(vmin, vmax) = locs[[0, -1]]
if vmin == vmax:
vmin -= 1
vmax += 1
return nonsingular(vmin, vmax)
#####-------------------------------------------------------------------------
#---- --- Formatter ---
#####-------------------------------------------------------------------------
示例3: set_default_locators_and_formatters
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import Formatter [as 别名]
def set_default_locators_and_formatters(self, axis):
"""
Override to set up the locators and formatters to use with the
scale. This is only required if the scale requires custom
locators and formatters. Writing custom locators and
formatters is rather outside the scope of this example, but
there are many helpful examples in ``ticker.py``.
In our case, the Mercator example uses a fixed locator from
-90 to 90 degrees and a custom formatter class to put convert
the radians to degrees and put a degree symbol after the
value::
"""
class DegreeFormatter(Formatter):
def __call__(self, x, pos=None):
return "%d\N{DEGREE SIGN}" % np.degrees(x)
axis.set_major_locator(FixedLocator(
np.radians(np.arange(-90, 90, 10))))
axis.set_major_formatter(DegreeFormatter())
axis.set_minor_formatter(DegreeFormatter())
示例4: wrap_formatter
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import Formatter [as 别名]
def wrap_formatter(formatter):
"""
Wraps formatting function or string in
appropriate matplotlib formatter type.
"""
if isinstance(formatter, ticker.Formatter):
return formatter
elif callable(formatter):
args = [arg for arg in _getargspec(formatter).args
if arg != 'self']
wrapped = formatter
if len(args) == 1:
def wrapped(val, pos=None):
return formatter(val)
return ticker.FuncFormatter(wrapped)
elif isinstance(formatter, basestring):
if re.findall(r"\{(\w+)\}", formatter):
return ticker.StrMethodFormatter(formatter)
else:
return ticker.FormatStrFormatter(formatter)
示例5: set_major_formatter
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import Formatter [as 别名]
def set_major_formatter(self, formatter):
"""
Set the formatter to use for the major tick labels.
Parameters
----------
formatter : str or Formatter
The format or formatter to use.
"""
if isinstance(formatter, Formatter):
raise NotImplementedError() # figure out how to swap out formatter
elif isinstance(formatter, str):
self._formatter_locator.format = formatter
else:
raise TypeError("formatter should be a string or a Formatter "
"instance")
示例6: set_major_formatter
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import Formatter [as 别名]
def set_major_formatter(self, formatter):
"""
Set the formatter of the major ticker.
Parameters
----------
formatter : ~matplotlib.ticker.Formatter
"""
if not isinstance(formatter, mticker.Formatter):
raise TypeError("formatter argument should be instance of "
"matplotlib.ticker.Formatter")
self.isDefault_majfmt = False
self.major.formatter = formatter
formatter.set_axis(self)
self.stale = True
示例7: set_minor_formatter
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import Formatter [as 别名]
def set_minor_formatter(self, formatter):
"""
Set the formatter of the minor ticker.
Parameters
----------
formatter : ~matplotlib.ticker.Formatter
"""
if not isinstance(formatter, mticker.Formatter):
raise TypeError("formatter argument should be instance of "
"matplotlib.ticker.Formatter")
self.isDefault_minfmt = False
self.minor.formatter = formatter
formatter.set_axis(self)
self.stale = True
示例8: set_minor_formatter
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import Formatter [as 别名]
def set_minor_formatter(self, formatter):
"""
Set the formatter of the minor ticker.
Parameters
----------
formatter : ~matplotlib.ticker.Formatter
"""
if not isinstance(formatter, mticker.Formatter):
raise TypeError("formatter argument should be instance of "
"matplotlib.ticker.Formatter")
self.isDefault_minfmt = False
self.minor.formatter = formatter
formatter.set_axis(self)
self.stale = True
示例9: set_major_formatter
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import Formatter [as 别名]
def set_major_formatter(self, formatter):
"""
Set the formatter of the major ticker.
Parameters
----------
formatter : `~matplotlib.ticker.Formatter`
"""
if not isinstance(formatter, mticker.Formatter):
raise TypeError("formatter argument should be instance of "
"matplotlib.ticker.Formatter")
self.isDefault_majfmt = False
self.major.formatter = formatter
formatter.set_axis(self)
self.stale = True
示例10: set_minor_formatter
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import Formatter [as 别名]
def set_minor_formatter(self, formatter):
"""
Set the formatter of the minor ticker.
Parameters
----------
formatter : `~matplotlib.ticker.Formatter`
"""
if not isinstance(formatter, mticker.Formatter):
raise TypeError("formatter argument should be instance of "
"matplotlib.ticker.Formatter")
self.isDefault_minfmt = False
self.minor.formatter = formatter
formatter.set_axis(self)
self.stale = True