本文整理汇总了Python中matplotlib.ticker.LogLocator方法的典型用法代码示例。如果您正苦于以下问题:Python ticker.LogLocator方法的具体用法?Python ticker.LogLocator怎么用?Python ticker.LogLocator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.ticker
的用法示例。
在下文中一共展示了ticker.LogLocator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _autolev
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def _autolev(self, z, N):
"""
Select contour levels to span the data.
We need two more levels for filled contours than for
line contours, because for the latter we need to specify
the lower and upper boundary of each range. For example,
a single contour boundary, say at z = 0, requires only
one contour line, but two filled regions, and therefore
three levels to provide boundaries for both regions.
"""
if self.locator is None:
if self.logscale:
self.locator = ticker.LogLocator()
else:
self.locator = ticker.MaxNLocator(N + 1)
zmax = self.zmax
zmin = self.zmin
lev = self.locator.tick_values(zmin, zmax)
self._auto = True
if self.filled:
return lev
# For line contours, drop levels outside the data range.
return lev[(lev > zmin) & (lev < zmax)]
示例2: _select_locator
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def _select_locator(self, formatter):
'''
select a suitable locator
'''
if self.boundaries is None:
if isinstance(self.norm, colors.NoNorm):
nv = len(self._values)
base = 1 + int(nv/10)
locator = ticker.IndexLocator(base=base, offset=0)
elif isinstance(self.norm, colors.BoundaryNorm):
b = self.norm.boundaries
locator = ticker.FixedLocator(b, nbins=10)
elif isinstance(self.norm, colors.LogNorm):
locator = ticker.LogLocator()
else:
locator = ticker.MaxNLocator(nbins=5)
else:
b = self._boundaries[self._inside]
locator = ticker.FixedLocator(b) #, nbins=10)
self.cbar_axis.set_major_locator(locator)
示例3: minorticks_on
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def minorticks_on(self):
"""
Display minor ticks on the axes.
Displaying minor ticks may reduce performance; you may turn them off
using `minorticks_off()` if drawing speed is a problem.
"""
for ax in (self.xaxis, self.yaxis):
scale = ax.get_scale()
if scale == 'log':
s = ax._scale
ax.set_minor_locator(mticker.LogLocator(s.base, s.subs))
elif scale == 'symlog':
s = ax._scale
ax.set_minor_locator(
mticker.SymmetricalLogLocator(s._transform, s.subs))
else:
ax.set_minor_locator(mticker.AutoMinorLocator())
示例4: test_colorbar_renorm
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def test_colorbar_renorm():
x, y = np.ogrid[-4:4:31j, -4:4:31j]
z = 120000*np.exp(-x**2 - y**2)
fig, ax = plt.subplots()
im = ax.imshow(z)
cbar = fig.colorbar(im)
norm = LogNorm(z.min(), z.max())
im.set_norm(norm)
cbar.set_norm(norm)
cbar.locator = LogLocator()
cbar.formatter = LogFormatter()
cbar.update_normal(im)
assert np.isclose(cbar.vmin, z.min())
norm = LogNorm(z.min() * 1000, z.max() * 1000)
im.set_norm(norm)
cbar.set_norm(norm)
cbar.update_normal(im)
assert np.isclose(cbar.vmin, z.min() * 1000)
assert np.isclose(cbar.vmax, z.max() * 1000)
示例5: _plot_walk
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def _plot_walk(self, ax, parameter, data, truth=None, extents=None, convolve=None, color=None, log_scale=False): # pragma: no cover
if extents is not None:
ax.set_ylim(extents)
assert convolve is None or isinstance(convolve, int), "Convolve must be an integer pixel window width"
x = np.arange(data.size)
ax.set_xlim(0, x[-1])
ax.set_ylabel(parameter)
if color is None:
color = "#0345A1"
ax.scatter(x, data, c=color, s=2, marker=".", edgecolors="none", alpha=0.5)
max_ticks = self.parent.config["max_ticks"]
if log_scale:
ax.set_yscale("log")
ax.yaxis.set_major_locator(LogLocator(numticks=max_ticks))
else:
ax.yaxis.set_major_locator(MaxNLocator(max_ticks, prune="lower"))
if convolve is not None:
color2 = self.parent.color_finder.scale_colour(color, 0.5)
filt = np.ones(convolve) / convolve
filtered = np.convolve(data, filt, mode="same")
ax.plot(x[:-1], filtered[:-1], ls=":", color=color2, alpha=1)
示例6: _select_locator
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def _select_locator(self, formatter):
'''
select a suitable locator
'''
if self.boundaries is None:
if isinstance(self.norm, colors.NoNorm):
nv = len(self._values)
base = 1 + int(nv/10)
locator = ticker.IndexLocator(base=base, offset=0)
elif isinstance(self.norm, colors.BoundaryNorm):
b = self.norm.boundaries
locator = ticker.FixedLocator(b, nbins=10)
elif isinstance(self.norm, colors.LogNorm):
locator = ticker.LogLocator()
else:
locator = ticker.MaxNLocator(nbins=5)
else:
b = self._boundaries[self._inside]
locator = ticker.FixedLocator(b)
self.cbar_axis.set_major_locator(locator)
示例7: __init__
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def __init__(self, colorbar, *args, **kwargs):
"""
_ColorbarLogLocator(colorbar, *args, **kwargs)
This ticker needs to know the *colorbar* so that it can access
its *vmin* and *vmax*. Otherwise it is the same as
`~.ticker.LogLocator`. The ``*args`` and ``**kwargs`` are the
same as `~.ticker.LogLocator`.
"""
self._colorbar = colorbar
super().__init__(*args, **kwargs)
示例8: _ticker
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def _ticker(self, locator, formatter):
'''
Return the sequence of ticks (colorbar data locations),
ticklabels (strings), and the corresponding offset string.
'''
if isinstance(self.norm, colors.NoNorm) and self.boundaries is None:
intv = self._values[0], self._values[-1]
else:
intv = self.vmin, self.vmax
locator.create_dummy_axis(minpos=intv[0])
formatter.create_dummy_axis(minpos=intv[0])
locator.set_view_interval(*intv)
locator.set_data_interval(*intv)
formatter.set_view_interval(*intv)
formatter.set_data_interval(*intv)
b = np.array(locator())
if isinstance(locator, ticker.LogLocator):
eps = 1e-10
b = b[(b <= intv[1] * (1 + eps)) & (b >= intv[0] * (1 - eps))]
else:
eps = (intv[1] - intv[0]) * 1e-10
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]
self._manual_tick_data_values = b
ticks = self._locate(b)
ticklabels = formatter.format_ticks(b)
offset_string = formatter.get_offset()
return ticks, ticklabels, offset_string
示例9: minorticks_on
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def minorticks_on(self):
'Add autoscaling minor ticks to the axes.'
for ax in (self.xaxis, self.yaxis):
if ax.get_scale() == 'log':
s = ax._scale
ax.set_minor_locator(mticker.LogLocator(s.base, s.subs))
else:
ax.set_minor_locator(mticker.AutoMinorLocator())
示例10: test_LogLocator
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def test_LogLocator():
loc = mticker.LogLocator(numticks=5)
assert_raises(ValueError, loc.tick_values, 0, 1000)
test_value = np.array([1.00000000e-05, 1.00000000e-03, 1.00000000e-01,
1.00000000e+01, 1.00000000e+03, 1.00000000e+05,
1.00000000e+07, 1.000000000e+09])
assert_almost_equal(loc.tick_values(0.001, 1.1e5), test_value)
loc = mticker.LogLocator(base=2)
test_value = np.array([0.5, 1., 2., 4., 8., 16., 32., 64., 128., 256.])
assert_almost_equal(loc.tick_values(1, 100), test_value)
示例11: __init__
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def __init__(self, colorbar, *args, **kwargs):
"""
_ColorbarLogLocator(colorbar, *args, **kwargs)
This ticker needs to know the *colorbar* so that it can access
its *vmin* and *vmax*. Otherwise it is the same as
`~.ticker.LogLocator`. The ``*args`` and ``**kwargs`` are the
same as `~.ticker.LogLocator`.
"""
self._colorbar = colorbar
ticker.LogLocator.__init__(self, *args, **kwargs)
示例12: tick_values
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def tick_values(self, vmin, vmax):
vmin = self._colorbar.norm.vmin
vmax = self._colorbar.norm.vmax
ticks = ticker.LogLocator.tick_values(self, vmin, vmax)
return ticks[(ticks >= vmin) & (ticks <= vmax)]
示例13: _ticker
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def _ticker(self, locator, formatter):
'''
Return the sequence of ticks (colorbar data locations),
ticklabels (strings), and the corresponding offset string.
'''
if isinstance(self.norm, colors.NoNorm) and self.boundaries is None:
intv = self._values[0], self._values[-1]
else:
intv = self.vmin, self.vmax
locator.create_dummy_axis(minpos=intv[0])
formatter.create_dummy_axis(minpos=intv[0])
locator.set_view_interval(*intv)
locator.set_data_interval(*intv)
formatter.set_view_interval(*intv)
formatter.set_data_interval(*intv)
b = np.array(locator())
if isinstance(locator, ticker.LogLocator):
eps = 1e-10
b = b[(b <= intv[1] * (1 + eps)) & (b >= intv[0] * (1 - eps))]
else:
eps = (intv[1] - intv[0]) * 1e-10
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]
self._tick_data_values = b
ticks = self._locate(b)
formatter.set_locs(b)
ticklabels = [formatter(t, i) for i, t in enumerate(b)]
offset_string = formatter.get_offset()
return ticks, ticklabels, offset_string
示例14: _ticker
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def _ticker(self, locator, formatter):
'''
Return the sequence of ticks (colorbar data locations),
ticklabels (strings), and the corresponding offset string.
'''
if isinstance(self.norm, colors.NoNorm) and self.boundaries is None:
intv = self._values[0], self._values[-1]
else:
intv = self.vmin, self.vmax
locator.create_dummy_axis(minpos=intv[0])
formatter.create_dummy_axis(minpos=intv[0])
locator.set_view_interval(*intv)
locator.set_data_interval(*intv)
formatter.set_view_interval(*intv)
formatter.set_data_interval(*intv)
b = np.array(locator())
if isinstance(locator, ticker.LogLocator):
eps = 1e-10
b = b[(b <= intv[1] * (1 + eps)) & (b >= intv[0] * (1 - eps))]
else:
eps = (intv[1] - intv[0]) * 1e-10
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]
self._manual_tick_data_values = b
ticks = self._locate(b)
formatter.set_locs(b)
ticklabels = [formatter(t, i) for i, t in enumerate(b)]
offset_string = formatter.get_offset()
return ticks, ticklabels, offset_string
示例15: test_basic
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import LogLocator [as 别名]
def test_basic(self):
loc = mticker.LogLocator(numticks=5)
with pytest.raises(ValueError):
loc.tick_values(0, 1000)
test_value = np.array([1.00000000e-05, 1.00000000e-03, 1.00000000e-01,
1.00000000e+01, 1.00000000e+03, 1.00000000e+05,
1.00000000e+07, 1.000000000e+09])
assert_almost_equal(loc.tick_values(0.001, 1.1e5), test_value)
loc = mticker.LogLocator(base=2)
test_value = np.array([0.5, 1., 2., 4., 8., 16., 32., 64., 128., 256.])
assert_almost_equal(loc.tick_values(1, 100), test_value)