本文整理汇总了Python中matplotlib.ticker.LogFormatterExponent方法的典型用法代码示例。如果您正苦于以下问题:Python ticker.LogFormatterExponent方法的具体用法?Python ticker.LogFormatterExponent怎么用?Python ticker.LogFormatterExponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.ticker
的用法示例。
在下文中一共展示了ticker.LogFormatterExponent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_LogFormatterExponent
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogFormatterExponent [as 别名]
def test_LogFormatterExponent():
class FakeAxis(object):
"""Allow Formatter to be called without having a "full" plot set up."""
def get_view_interval(self):
return 1, 10
i = np.arange(-3, 4, dtype=float)
expected_result = ['-3', '-2', '-1', '0', '1', '2', '3']
for base in [2, 5, 10, np.pi, np.e]:
formatter = mticker.LogFormatterExponent(base=base)
formatter.axis = FakeAxis()
vals = base**i
labels = [formatter(x, pos) for (x, pos) in zip(vals, i)]
nose.tools.assert_equal(labels, expected_result)
# Should be a blank string for non-integer powers if labelOnlyBase=True
formatter = mticker.LogFormatterExponent(base=10, labelOnlyBase=True)
formatter.axis = FakeAxis()
nose.tools.assert_equal(formatter(10**0.1), '')
# Otherwise, non-integer powers should be nicely formatted
locs = np.array([0.1, 0.00001, np.pi, 0.2, -0.2, -0.00001])
i = range(len(locs))
expected_result = ['0.1', '1e-05', '3.14', '0.2', '-0.2', '-1e-05']
for base in [2, 5, 10, np.pi, np.e]:
formatter = mticker.LogFormatterExponent(base, labelOnlyBase=False)
formatter.axis = FakeAxis()
vals = base**locs
labels = [formatter(x, pos) for (x, pos) in zip(vals, i)]
nose.tools.assert_equal(labels, expected_result)
示例2: test_basic
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogFormatterExponent [as 别名]
def test_basic(self, labelOnlyBase, base, exponent, locs, positions,
expected):
formatter = mticker.LogFormatterExponent(base=base,
labelOnlyBase=labelOnlyBase)
formatter.axis = FakeAxis(1, base**exponent)
vals = base**locs
labels = [formatter(x, pos) for (x, pos) in zip(vals, positions)]
assert labels == expected
示例3: test_blank
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogFormatterExponent [as 别名]
def test_blank(self):
# Should be a blank string for non-integer powers if labelOnlyBase=True
formatter = mticker.LogFormatterExponent(base=10, labelOnlyBase=True)
formatter.axis = FakeAxis()
assert formatter(10**0.1) == ''