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)
python类NullLocator()的实例源码
plotting.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def 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,
interpolation='nearest',
extent=exts)
ax.xaxis.set_major_locator(MT.NullLocator())
ax.yaxis.set_major_locator(MT.NullLocator())
return ax
def 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 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, self.XLABELTEXTTOP, '', ha='right', va='top', fontsize=self.NUMBERFONTSIZE)
self.xlabel_ax.set_xlim(0.0, 1.0)
self.xlabel_ax.set_ylim(0.0, 1.0)
def 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, '', ha='left', va='center', fontsize=self.TEXTFONTSIZE, rotation=90)
self.ylabel_ax.text(self.YLABELTEXTRIGHT, self.YLABELTEXTVMARGIN, '', ha='right', va='bottom', fontsize=self.NUMBERFONTSIZE)
self.ylabel_ax.text(self.YLABELTEXTRIGHT, 1.0 - self.YLABELTEXTVMARGIN, '', ha='right', va='top', fontsize=self.NUMBERFONTSIZE)
self.ylabel_ax.set_xlim(0.0, 1.0)
self.ylabel_ax.set_ylim(0.0, 1.0)
def 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, 0.5, self.zlabel, ha='right', va='center', fontsize=self.TEXTFONTSIZE, rotation=270)
self.zlabel_ax.set_xlim(0.0, 1.0)
self.zlabel_ax.set_ylim(0.0, 1.0)
def set_default_locators_and_formatters(self, axis):
axis.set_major_locator(NullLocator())
axis.set_major_formatter(NullFormatter())
axis.set_minor_formatter(NullFormatter())
def 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 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, '', ha='left', va='center', fontsize=self.TEXTFONTSIZE, rotation=90)
self.ylabel_ax.text(self.YLABELTEXTRIGHT, self.YLABELTEXTVMARGIN, '', ha='right', va='bottom', fontsize=self.NUMBERFONTSIZE)
self.ylabel_ax.text(self.YLABELTEXTRIGHT, 1.0 - self.YLABELTEXTVMARGIN, '', ha='right', va='top', fontsize=self.NUMBERFONTSIZE)
self.ylabel_ax.set_xlim(0.0, 1.0)
self.ylabel_ax.set_ylim(0.0, 1.0)
def 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, 0.5, self.zlabel, ha='right', va='center', fontsize=self.TEXTFONTSIZE, rotation=270)
self.zlabel_ax.set_xlim(0.0, 1.0)
self.zlabel_ax.set_ylim(0.0, 1.0)
def 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.