本文整理汇总了Python中matplotlib.gridspec.GridSpec.set_height_ratios方法的典型用法代码示例。如果您正苦于以下问题:Python GridSpec.set_height_ratios方法的具体用法?Python GridSpec.set_height_ratios怎么用?Python GridSpec.set_height_ratios使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.gridspec.GridSpec
的用法示例。
在下文中一共展示了GridSpec.set_height_ratios方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_azel
# 需要导入模块: from matplotlib.gridspec import GridSpec [as 别名]
# 或者: from matplotlib.gridspec.GridSpec import set_height_ratios [as 别名]
def plot_azel(data, task, pd, resolution=100, cbar=True,
subplot_spec=None, fig=None, label='', vscale=None,
labelpad=0.025, frame_width=None):
'''
Parameters
----------
data : ndarray
shape (ntime, ntask)
task : ndarray
shape (ntask, 6)
pd : ndarray
shape (3,)
resolution : int
number of pixels for azel images
cbar : bool
draw a colour bar?
subplot_spec : matplotlib SubplotSpec or None
a SubplotSpec in which to draw the plot
a `fig` must also be supplied
fig : matplotlib Figure or None
only used if subplot_spec is not None
existing figure in which to draw plot
vscale : tuple (float, float)
min and max color scale values
labelpad : float
spacing between top of plots and label
'''
assert(np.rank(data) == 2)
assert(data.shape[1] == task.shape[0])
assert(pd.shape == (3,))
assert(type(resolution) == int)
assert((subplot_spec == None) == (fig == None))
assert((vscale == None) | ((type(vscale) == tuple)))
if type(vscale) == tuple:
assert((len(vscale) == 2))
assert(np.isscalar(vscale[0]))
assert((type(cbar) == bool) | (cbar == 'ghost'))
ntime = data.shape[0]
if vscale != None:
vmin = vscale[0]
vmax = vscale[1]
else:
vmin = np.min(data)
vmax = np.max(data)
co = sort.get_center_out(task)
height_ratios = [1,] * ntime
if cbar:
extra = 1
height_ratios += [0.3,]
else:
extra = 0
if subplot_spec == None:
# make our own figure
w = 1.5
h = 7
fig = plt.figure(figsize=(w, h))
gs = GridSpec(ntime + extra, 2, hspace=0.0, wspace=0.0,
left=0, right=1., bottom=0,
height_ratios=height_ratios)
top = gs[0,0].get_position(fig).y1
left = gs[0,0].get_position(fig).x0
right = gs[0,1].get_position(fig).x1
center = (left + right) / 2.
else:
# subplot_spec != None
#m = ptl.subplot_spec2margins(subplot_spec, fig)
#ax_rects = ptl.get_ax_rects(np.arange(ntime * 2), 2, ntime,
# margin=m, direction='col')
gs = GridSpecFromSubplotSpec(ntime + extra, 2, hspace=0, wspace=0,
subplot_spec=subplot_spec)
#gs.update(left=0.1, right=0.9, bottom=0.1, hspace=0.05, wspace=0.05)
gs.set_height_ratios(height_ratios)
box = subplot_spec.get_position(fig)
top = box.y1
center = (box.x0 + box.x1) / 2.
for i, which in enumerate([co, ~co]):
mapped_data = _map_data(data[:,which], task[which], pd, resolution)
for j in xrange(ntime):
ax = fig.add_subplot(gs[j,i])
#ax = fig.add_axes(ax_rects[i * ntime + j])
ax.imshow(mapped_data[j], vmin=vmin, vmax=vmax, aspect='auto')
ax.set_xticks([])
ax.set_yticks([])
if frame_width != None:
for loc, sp in ax.spines.iteritems():
sp.set_linewidth = frame_width
if label != '':
fig.text(center, top + labelpad, label, fontsize='large', ha='center')
# explicit boolean check to avoid cbar == 'ghost' case
if cbar == True:
cbax = fig.add_subplot(gs[-1,:], aspect=0.15)
cb = plt.colorbar(ax.images[0], cbax, orientation='horizontal')
clim = cb.get_clim()
cb.set_ticks(clim)
#.........这里部分代码省略.........