本文整理汇总了Python中matplotlib.ticker.AutoLocator方法的典型用法代码示例。如果您正苦于以下问题:Python ticker.AutoLocator方法的具体用法?Python ticker.AutoLocator怎么用?Python ticker.AutoLocator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.ticker
的用法示例。
在下文中一共展示了ticker.AutoLocator方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _remove_labels_from_axis
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import AutoLocator [as 别名]
def _remove_labels_from_axis(axis):
for t in axis.get_majorticklabels():
t.set_visible(False)
try:
# set_visible will not be effective if
# minor axis has NullLocator and NullFormattor (default)
import matplotlib.ticker as ticker
if isinstance(axis.get_minor_locator(), ticker.NullLocator):
axis.set_minor_locator(ticker.AutoLocator())
if isinstance(axis.get_minor_formatter(), ticker.NullFormatter):
axis.set_minor_formatter(ticker.FormatStrFormatter(''))
for t in axis.get_minorticklabels():
t.set_visible(False)
except Exception: # pragma no cover
raise
axis.get_label().set_visible(False)
示例2: axisinfo
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import AutoLocator [as 别名]
def axisinfo(unit, axis):
'return AxisInfo instance for x and unit'
if unit == radians:
return units.AxisInfo(
majloc=ticker.MultipleLocator(base=np.pi/2),
majfmt=ticker.FuncFormatter(rad_fn),
label=unit.fullname,
)
elif unit == degrees:
return units.AxisInfo(
majloc=ticker.AutoLocator(),
majfmt=ticker.FormatStrFormatter(r'$%i^\circ$'),
label=unit.fullname,
)
elif unit is not None:
if hasattr(unit, 'fullname'):
return units.AxisInfo(label=unit.fullname)
elif hasattr(unit, 'unit'):
return units.AxisInfo(label=unit.unit.fullname)
return None
示例3: axisinfo
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import AutoLocator [as 别名]
def axisinfo(unit, axis):
if unit != 'time':
return None
majloc = AutoLocator()
majfmt = TimeFormatter(majloc)
return units.AxisInfo(majloc=majloc, majfmt=majfmt, label='time')
示例4: cla
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import AutoLocator [as 别名]
def cla(self):
'clear the current axis'
self.set_major_locator(mticker.AutoLocator())
self.set_major_formatter(mticker.ScalarFormatter())
self.set_minor_locator(mticker.NullLocator())
self.set_minor_formatter(mticker.NullFormatter())
self.set_label_text('')
self._set_artist_props(self.label)
# Keep track of setting to the default value, this allows use to know
# if any of the following values is explicitly set by the user, so as
# to not overwrite their settings with any of our 'auto' settings.
self.isDefault_majloc = True
self.isDefault_minloc = True
self.isDefault_majfmt = True
self.isDefault_minfmt = True
self.isDefault_label = True
# Clear the callback registry for this axis, or it may "leak"
self.callbacks = cbook.CallbackRegistry()
# whether the grids are on
self._gridOnMajor = rcParams['axes.grid']
self._gridOnMinor = False
self.label.set_text('')
self._set_artist_props(self.label)
self.reset_ticks()
self.converter = None
self.units = None
self.set_units(None)
示例5: cla
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import AutoLocator [as 别名]
def cla(self):
'clear the current axis'
self.set_major_locator(mticker.AutoLocator())
self.set_major_formatter(mticker.ScalarFormatter())
self.set_minor_locator(mticker.NullLocator())
self.set_minor_formatter(mticker.NullFormatter())
self.set_label_text('')
self._set_artist_props(self.label)
# Keep track of setting to the default value, this allows use to know
# if any of the following values is explicitly set by the user, so as
# to not overwrite their settings with any of our 'auto' settings.
self.isDefault_majloc = True
self.isDefault_minloc = True
self.isDefault_majfmt = True
self.isDefault_minfmt = True
self.isDefault_label = True
# Clear the callback registry for this axis, or it may "leak"
self.callbacks = cbook.CallbackRegistry()
# whether the grids are on
self._gridOnMajor = rcParams['axes.grid'] and (rcParams['axes.grid.which'] in ('both','major'))
self._gridOnMinor = rcParams['axes.grid'] and (rcParams['axes.grid.which'] in ('both','minor'))
self.label.set_text('')
self._set_artist_props(self.label)
self.reset_ticks()
self.converter = None
self.units = None
self.set_units(None)
示例6: create_slice
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import AutoLocator [as 别名]
def create_slice(self, context):
""" :type context: dict """
model = self._model
axes = self._image.axes
""" :type: matplotlib.axes.Axes """
axes.set_title(model.title, fontsize=12)
axes.tick_params(axis='both')
axes.set_ylabel(model.y_axis_name, fontsize=9)
axes.set_xlabel(model.x_axis_name, fontsize=9)
axes.get_xaxis().set_major_formatter(FuncFormatter(model.x_axis_formatter))
axes.get_xaxis().set_major_locator(AutoLocator())
axes.get_yaxis().set_major_formatter(FuncFormatter(model.y_axis_formatter))
axes.get_yaxis().set_major_locator(AutoLocator())
for label in (axes.get_xticklabels() + axes.get_yticklabels()):
label.set_fontsize(9)
self._reset_zoom()
axes.add_patch(self._vertical_indicator)
axes.add_patch(self._horizontal_indicator)
self._update_indicators(context)
self._image.set_cmap(cmap=context['colormap'])
self._view_limits = context["view_limits"][self._model.index_direction['name']]
if model.data is not None:
self._image.set_data(model.data)
示例7: update_plot
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import AutoLocator [as 别名]
def update_plot(self):
if len(self.Plotsignals) == 0:
return
self.ax.clear()
for Plotsignal in self.Plotsignals:
if Plotsignal.plotenable:
if Plotsignal.plotnormalise:
data = Plotsignal.get_normalised_values()*100
self.ax.plot(data, color=Plotsignal.plotcolor)
else:
data = Plotsignal.get_values()
self.ax.plot(convert_to_si(Plotsignal.unit,data)[1], color=Plotsignal.plotcolor)
self.ax.grid(True)
self.ax.get_yaxis().tick_right()
self.ax.get_yaxis().set_label_position("right")
self.ax.get_yaxis().set_visible(True)
self.ax.get_xaxis().set_visible(False)
all_normalised = True
all_same_unit = True
unit = ""
iter = self.signalstore.get_iter(0)
while iter is not None:
if self.signalstore[iter][0] == True:
if unit == "":
unit = self.signalstore[iter][4]
if self.signalstore[iter][1] == False:
all_normalised = False
if self.signalstore[iter][4] != unit:
all_same_unit = False
if not all_normalised and not all_same_unit:
break
iter = self.signalstore.iter_next(iter)
if all_normalised:
self.ax.set_yticks(np.arange(0, 101, step=25))
self.ax.set_ylabel('Percent [%]')
else:
self.ax.yaxis.set_major_locator(AutoLocator())
if all_same_unit:
self.ax.set_ylabel(unit)
else:
self.ax.set_ylabel("")
self.canvas.draw()
self.canvas.flush_events()
示例8: mirror
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import AutoLocator [as 别名]
def mirror(spec_top: MsmsSpectrum, spec_bottom: MsmsSpectrum,
spectrum_kws: Optional[Dict] = None, ax: Optional[plt.Axes] = None)\
-> plt.Axes:
"""
Mirror plot two MS/MS spectra.
Parameters
----------
spec_top : MsmsSpectrum
The spectrum to be plotted on the top.
spec_bottom : MsmsSpectrum
The spectrum to be plotted on the bottom.
spectrum_kws : Optional[Dict], optional
Keyword arguments for `plot.spectrum`.
ax : Optional[plt.Axes], optional
Axes instance on which to plot the spectrum. If None the current Axes
instance is used.
Returns
-------
plt.Axes
The matplotlib Axes instance on which the spectra are plotted.
"""
if ax is None:
ax = plt.gca()
if spectrum_kws is None:
spectrum_kws = {}
# Top spectrum.
spectrum(spec_top, mirror_intensity=False, ax=ax, **spectrum_kws)
y_max = ax.get_ylim()[1]
# Mirrored bottom spectrum.
spectrum(spec_bottom, mirror_intensity=True, ax=ax, **spectrum_kws)
y_min = ax.get_ylim()[0]
ax.set_ylim(y_min, y_max)
ax.axhline(0, color='#9E9E9E', zorder=10)
# Update axes so that both spectra fit.
min_mz = max([0, math.floor(spec_top.mz[0] / 100 - 1) * 100,
math.floor(spec_bottom.mz[0] / 100 - 1) * 100])
max_mz = max([math.ceil(spec_top.mz[-1] / 100 + 1) * 100,
math.ceil(spec_bottom.mz[-1] / 100 + 1) * 100])
ax.set_xlim(min_mz, max_mz)
ax.yaxis.set_major_locator(mticker.AutoLocator())
ax.yaxis.set_minor_locator(mticker.AutoMinorLocator())
ax.yaxis.set_major_formatter(mticker.FuncFormatter(
lambda x, pos: f'{abs(x):.0%}'))
return ax
示例9: _ticker
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import AutoLocator [as 别名]
def _ticker(self):
'''
Return the sequence of ticks (colorbar data locations),
ticklabels (strings), and the corresponding offset string.
'''
locator = self.locator
formatter = self.formatter
if locator is None:
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(subs='all')
elif isinstance(self.norm, colors.SymLogNorm):
# The subs setting here should be replaced
# by logic in the locator.
locator = ticker.SymmetricalLogLocator(
subs=np.arange(1, 10),
linthresh=self.norm.linthresh,
base=10)
else:
if mpl.rcParams['_internal.classic_mode']:
locator = ticker.MaxNLocator()
else:
locator = ticker.AutoLocator()
else:
b = self._boundaries[self._inside]
locator = ticker.FixedLocator(b, nbins=10)
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