Python matplotlib.ticker 模块,NullLocator() 实例源码
我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用matplotlib.ticker.NullLocator()。
def @H_502_26@_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)
def @H_502_26@scaledimage(W, pixwidth=1, ax=None, grayscale=True):
"""
Do intensity plot,similar to MATLAB imagesc()
W = intensity matrix to visualize
pixwidth = size of each W element
ax = matplotlib Axes to draw on
grayscale = use grayscale color map
Rely on caller to .show()
"""
# N = rows,M = column
(N, M) = W.shape
# Need to create a new Axes?
if(ax == None):
ax = plt.figure().gca()
# extents = Left Right Bottom Top
exts = (0, pixwidth * M, 0, pixwidth * N)
if(grayscale):
ax.imshow(W,
interpolation='nearest',
cmap=CM.gray,
extent=exts)
else:
ax.imshow(W,
extent=exts)
ax.xaxis.set_major_locator(MT.NullLocator())
ax.yaxis.set_major_locator(MT.NullLocator())
return ax
def @H_502_26@set_default_locators_and_formatters(self, axis):
"""
Just took the code from LinearScale.set_default_locators_and_formatters
"""
axis.set_major_locator(AutoLocator())
axis.set_major_formatter(ScalarFormatter())
axis.set_minor_locator(NullLocator())
axis.set_minor_formatter(NullFormatter())
def @H_502_26@create_xlabel(self):
rect = [self.MAINAXLEFT, self.XLABELBottOM, self.MAINAXWIDTH, self.XLABELHEIGHT]
self.xlabel_ax = self.figure.add_axes(rect)
self.xlabel_ax.xaxis.set_major_locator(NullLocator())
self.xlabel_ax.yaxis.set_major_locator(NullLocator())
self.xlabel_ax.text(0.5, self.XLABELTEXTBottOM, '', ha='center', va='bottom', fontsize=self.TEXTFONTSIZE)
self.xlabel_ax.text(self.XLABELTEXTHMARGIN, self.XLABELTEXTTOP, ha='left', va='top', fontsize=self.NUMBERFONTSIZE)
self.xlabel_ax.text(1.0 - self.XLABELTEXTHMARGIN, ha='right', fontsize=self.NUMBERFONTSIZE)
self.xlabel_ax.set_xlim(0.0, 1.0)
self.xlabel_ax.set_ylim(0.0, 1.0)
def @H_502_26@create_ylabel(self):
rect = [self.YLABELLEFT, self.MAINAXBottOM, self.YLABELWIDTH, self.MAINAXHEIGHT]
self.ylabel_ax = self.figure.add_axes(rect)
self.ylabel_ax.xaxis.set_major_locator(NullLocator())
self.ylabel_ax.yaxis.set_major_locator(NullLocator())
self.ylabel_ax.text(self.YLABELTEXTLEFT, 0.5, va='center', fontsize=self.TEXTFONTSIZE, rotation=90)
self.ylabel_ax.text(self.YLABELTEXTRIGHT, self.YLABELTEXTVMARGIN, fontsize=self.NUMBERFONTSIZE)
self.ylabel_ax.text(self.YLABELTEXTRIGHT, 1.0 - self.YLABELTEXTVMARGIN, fontsize=self.NUMBERFONTSIZE)
self.ylabel_ax.set_xlim(0.0, 1.0)
self.ylabel_ax.set_ylim(0.0, 1.0)
def @H_502_26@clear_zlabel(self):
self.zlabel_ax.clear()
self.zlabel_ax.xaxis.set_major_locator(NullLocator())
self.zlabel_ax.yaxis.set_major_locator(NullLocator())
self.zlabel_ax.text(self.ZLABELTEXTRIGHT, self.zlabel, rotation=270)
self.zlabel_ax.set_xlim(0.0, 1.0)
self.zlabel_ax.set_ylim(0.0, 1.0)
def @H_502_26@create_and_prepare_axes(figure, extent):
#import matplotlib.figure.figure.text
ax = Axes(figure, extent)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.xaxis.set_major_locator(NullLocator())
ax.yaxis.set_major_locator(NullLocator())
figure.add_axes(ax)
return ax
def @H_502_26@clear_zlabel(self):
self.zlabel_ax.clear()
self.zlabel_ax.xaxis.set_major_locator(NullLocator())
self.zlabel_ax.yaxis.set_major_locator(NullLocator())
self.zlabel_ax.text(self.ZLABELTEXTRIGHT, 1.0)
def @H_502_26@cla(self):
"""Identical to Axes.cla (This docstring is overwritten)."""
Axes.cla(self)
# Set grid defaults...
self.set_longitude_grid(10)
self.set_latitude_grid(10)
self.set_longitude_grid_ends(80)
# Hide all ticks and tick labels for the "native" lon and lat axes
self.xaxis.set_minor_locator(NullLocator())
self.yaxis.set_minor_locator(NullLocator())
self.xaxis.set_ticks_position('none')
self.yaxis.set_ticks_position('none')
self.xaxis.set_tick_params(label1On=False)
self.yaxis.set_tick_params(label1On=False)
# Set the grid on or off based on the rc params.
self.grid(mpl.rcParams['axes.grid'])
# Set the default limits (so that the "native" ticklabels will be
# correct if they're turned back on)...
Axes.set_xlim(self, -2 * self.horizon, 2 * self.horizon)
Axes.set_ylim(self, -np.pi / 2.0, np.pi / 2.0)
# Set up the azimuth ticks.
self._polar.set_theta_offset(np.radians(self.rotation + 90))
self._polar.set_theta_direction(-1)
self._polar.grid(False)
self._polar.set_rticks([])
# Use default docstring,as usage is identical.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。