本文整理汇总了Python中matplotlib.colorbar.ColorbarBase.update_ticks方法的典型用法代码示例。如果您正苦于以下问题:Python ColorbarBase.update_ticks方法的具体用法?Python ColorbarBase.update_ticks怎么用?Python ColorbarBase.update_ticks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.colorbar.ColorbarBase
的用法示例。
在下文中一共展示了ColorbarBase.update_ticks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BaseSlicer
# 需要导入模块: from matplotlib.colorbar import ColorbarBase [as 别名]
# 或者: from matplotlib.colorbar.ColorbarBase import update_ticks [as 别名]
#.........这里部分代码省略.........
self._colorbar_ax = figure.add_axes(lt_wid_top_ht, axis_bgcolor='w')
our_cmap = im.cmap
# edge case where the data has a single value
# yields a cryptic matplotlib error message
# when trying to plot the color bar
nb_ticks = 5 if im.norm.vmin != im.norm.vmax else 1
ticks = np.linspace(im.norm.vmin, im.norm.vmax, nb_ticks)
bounds = np.linspace(im.norm.vmin, im.norm.vmax, our_cmap.N)
# some colormap hacking
cmaplist = [our_cmap(i) for i in range(our_cmap.N)]
istart = int(im.norm(-offset, clip=True) * (our_cmap.N - 1))
istop = int(im.norm(offset, clip=True) * (our_cmap.N - 1))
for i in range(istart, istop):
cmaplist[i] = (0.5, 0.5, 0.5, 1.) # just an average gray color
if im.norm.vmin == im.norm.vmax: # len(np.unique(data)) == 1 ?
return
else:
our_cmap = our_cmap.from_list('Custom cmap', cmaplist, our_cmap.N)
self._cbar = ColorbarBase(
self._colorbar_ax, ticks=ticks, norm=im.norm,
orientation='vertical', cmap=our_cmap, boundaries=bounds,
spacing='proportional')
self._cbar.set_ticklabels(["%.2g" % t for t in ticks])
self._colorbar_ax.yaxis.tick_left()
tick_color = 'w' if self._black_bg else 'k'
for tick in self._colorbar_ax.yaxis.get_ticklabels():
tick.set_color(tick_color)
self._colorbar_ax.yaxis.set_tick_params(width=0)
self._cbar.update_ticks()
def add_edges(self, img, color='r'):
""" Plot the edges of a 3D map in all the views.
Parameters
-----------
map: 3D ndarray
The 3D map to be plotted. If it is a masked array, only
the non-masked part will be plotted.
affine: 4x4 ndarray
The affine matrix giving the transformation from voxel
indices to world space.
color: matplotlib color: string or (r, g, b) value
The color used to display the edge map
"""
img = reorder_img(img)
data = img.get_data()
affine = img.get_affine()
single_color_cmap = colors.ListedColormap([color])
data_bounds = get_bounds(data.shape, img.get_affine())
# For each ax, cut the data and plot it
for display_ax in self.axes.values():
try:
data_2d = display_ax.transform_to_2d(data, affine)
edge_mask = _edge_map(data_2d)
except IndexError:
# We are cutting outside the indices of the data
continue
display_ax.draw_2d(edge_mask, data_bounds, data_bounds,
type='imshow', cmap=single_color_cmap)