本文整理汇总了Python中matplotlib.ticker.LogFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python ticker.LogFormatter方法的具体用法?Python ticker.LogFormatter怎么用?Python ticker.LogFormatter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.ticker
的用法示例。
在下文中一共展示了ticker.LogFormatter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_y_axis
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogFormatter [as 别名]
def plot_y_axis(self, cbar_ax, plot_ax):
if self.properties['transform'] in ['log', 'log1p']:
# get a useful log scale
# that looks like [1, 2, 5, 10, 20, 50, 100, ... etc]
formatter = LogFormatter(10, labelOnlyBase=False)
aa = np.array([1, 2, 5])
tick_values = np.concatenate([aa * 10 ** x for x in range(10)])
try:
cobar = plt.colorbar(self.img, ticks=tick_values, format=formatter, ax=cbar_ax, fraction=0.95)
except AttributeError:
return
else:
try:
cobar = plt.colorbar(self.img, ax=cbar_ax, fraction=0.95)
except AttributeError:
return
cobar.solids.set_edgecolor("face")
cobar.ax.tick_params(labelsize='smaller')
cobar.ax.yaxis.set_ticks_position('left')
# adjust the labels of the colorbar
ticks = cobar.ax.get_yticks()
labels = cobar.ax.set_yticklabels(ticks.astype('float32'))
(vmin, vmax) = cobar.mappable.get_clim()
for idx in np.where(ticks == vmin)[0]:
# if the label is at the start of the colobar
# move it above avoid being cut or overlapping with other track
labels[idx].set_verticalalignment('bottom')
for idx in np.where(ticks == vmax)[0]:
# if the label is at the end of the colobar
# move it a bit inside to avoid overlapping
# with other labels
labels[idx].set_verticalalignment('top')
示例2: update_ticks
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogFormatter [as 别名]
def update_ticks(self):
"""
Force the update of the ticks and ticklabels. This must be
called whenever the tick locator and/or tick formatter changes.
"""
ax = self.ax
# get the locator and formatter. Defaults to
# self.locator if not None..
locator, formatter = self._get_ticker_locator_formatter()
if self.orientation == 'vertical':
long_axis, short_axis = ax.yaxis, ax.xaxis
else:
long_axis, short_axis = ax.xaxis, ax.yaxis
if self._use_auto_colorbar_locator():
_log.debug('Using auto colorbar locator on colorbar')
_log.debug('locator: %r', locator)
long_axis.set_major_locator(locator)
long_axis.set_major_formatter(formatter)
if type(self.norm) == colors.LogNorm:
long_axis.set_minor_locator(_ColorbarLogLocator(self,
base=10., subs='auto'))
long_axis.set_minor_formatter(
ticker.LogFormatter()
)
else:
_log.debug('Using fixed locator on colorbar')
ticks, ticklabels, offset_string = self._ticker(locator, formatter)
long_axis.set_ticks(ticks)
long_axis.set_ticklabels(ticklabels)
long_axis.get_major_formatter().set_offset_string(offset_string)
示例3: test_pprint
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogFormatter [as 别名]
def test_pprint(self, value, domain, expected):
fmt = mticker.LogFormatter()
label = fmt.pprint_val(value, domain)
assert label == expected
示例4: test_sublabel
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogFormatter [as 别名]
def test_sublabel(self):
# test label locator
fig, ax = plt.subplots()
ax.set_xscale('log')
ax.xaxis.set_major_locator(mticker.LogLocator(base=10, subs=[]))
ax.xaxis.set_minor_locator(mticker.LogLocator(base=10,
subs=np.arange(2, 10)))
ax.xaxis.set_major_formatter(mticker.LogFormatter(labelOnlyBase=True))
ax.xaxis.set_minor_formatter(mticker.LogFormatter(labelOnlyBase=False))
# axis range above 3 decades, only bases are labeled
ax.set_xlim(1, 1e4)
fmt = ax.xaxis.get_major_formatter()
fmt.set_locs(ax.xaxis.get_majorticklocs())
show_major_labels = [fmt(x) != ''
for x in ax.xaxis.get_majorticklocs()]
assert np.all(show_major_labels)
self._sub_labels(ax.xaxis, subs=[])
# For the next two, if the numdec threshold in LogFormatter.set_locs
# were 3, then the label sub would be 3 for 2-3 decades and (2,5)
# for 1-2 decades. With a threshold of 1, subs are not labeled.
# axis range at 2 to 3 decades
ax.set_xlim(1, 800)
self._sub_labels(ax.xaxis, subs=[])
# axis range at 1 to 2 decades
ax.set_xlim(1, 80)
self._sub_labels(ax.xaxis, subs=[])
# axis range at 0.4 to 1 decades, label subs 2, 3, 4, 6
ax.set_xlim(1, 8)
self._sub_labels(ax.xaxis, subs=[2, 3, 4, 6])
# axis range at 0 to 0.4 decades, label all
ax.set_xlim(0.5, 0.9)
self._sub_labels(ax.xaxis, subs=np.arange(2, 10, dtype=int))
示例5: test_LogFormatter_call
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogFormatter [as 别名]
def test_LogFormatter_call(self, val):
# test _num_to_string method used in __call__
temp_lf = mticker.LogFormatter()
temp_lf.axis = FakeAxis()
assert temp_lf(val) == str(val)
示例6: test_majlocator_type
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogFormatter [as 别名]
def test_majlocator_type():
fig, ax = plt.subplots()
with pytest.raises(TypeError):
ax.xaxis.set_major_locator(matplotlib.ticker.LogFormatter())
示例7: test_minlocator_type
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogFormatter [as 别名]
def test_minlocator_type():
fig, ax = plt.subplots()
with pytest.raises(TypeError):
ax.xaxis.set_minor_locator(matplotlib.ticker.LogFormatter())
示例8: __plot_colorbar
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogFormatter [as 别名]
def __plot_colorbar(self, img, orientation='vertical'):
if orientation == 'horizontal':
ax_divider = make_axes_locatable(self.ax)
if self.is_inverted:
cax = ax_divider.append_axes("top", size=0.09, pad=0.2)
else:
cax = ax_divider.append_axes("bottom", size=0.09, pad=0.2)
colorbar(img, cax=cax, orientation='horizontal')
else: # vertical
y_ax = self.y_ax
if self.properties['norm'] == 'log':
from matplotlib.ticker import LogFormatter
formatter = LogFormatter(10, labelOnlyBase=False)
aa = np.array([1, 2, 5])
c_min, c_max = self.matrix_val_range
def abs_inc(num):
if num != 0:
sign = num / abs(num)
return int(sign * abs(num + 1))
else:
return 1
lower_ = int(np.log10(c_min))
upper_ = abs_inc(int(np.log10(c_max)))
tick_values = np.concatenate([aa * 10 ** x for x in range(lower_, upper_)])
c_bar = plt.colorbar(img, ax=y_ax, ticks=tick_values, format=formatter, fraction=0.98)
else:
c_bar = plt.colorbar(img, ax=y_ax, fraction=0.98)
c_bar.solids.set_edgecolor("face")
c_bar.ax.tick_params(labelsize='smaller')
c_bar.ax.yaxis.set_ticks_position('left')