本文整理匯總了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