本文整理汇总了Python中matplotlib.gridspec.GridSpec.set_width_ratios方法的典型用法代码示例。如果您正苦于以下问题:Python GridSpec.set_width_ratios方法的具体用法?Python GridSpec.set_width_ratios怎么用?Python GridSpec.set_width_ratios使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.gridspec.GridSpec
的用法示例。
在下文中一共展示了GridSpec.set_width_ratios方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_abide_stripplots
# 需要导入模块: from matplotlib.gridspec import GridSpec [as 别名]
# 或者: from matplotlib.gridspec.GridSpec import set_width_ratios [as 别名]
def plot_abide_stripplots(inputs, figsize=(15, 2), out_file=None,
rating_label='rater_1', dpi=100):
import seaborn as sn
sn.set(style="whitegrid")
mdata = []
pp_cols = []
for X, Y, sitename in inputs:
sitedata, cols = read_dataset(X, Y, rate_label=rating_label,
binarize=False, site_name=sitename)
sitedata['database'] = [sitename] * len(sitedata)
if sitename == 'DS030':
sitedata['site'] = [sitename] * len(sitedata)
mdata.append(sitedata)
pp_cols.append(cols)
mdata = pd.concat(mdata)
pp_cols = pp_cols[0]
for col in mdata.columns.ravel().tolist():
if col.startswith('rater_') and col != rating_label:
del mdata[col]
mdata = mdata.loc[mdata[rating_label].notnull()]
for col in ['size_x', 'size_y', 'size_z', 'spacing_x', 'spacing_y', 'spacing_z']:
del mdata[col]
try:
pp_cols.remove(col)
except ValueError:
pass
zscored = zscore_dataset(mdata, excl_columns=[rating_label])
sites = list(set(mdata.site.values.ravel()))
nsites = len(sites)
# palette = ['dodgerblue', 'darkorange']
palette = ['limegreen', 'tomato']
if len(set(mdata[[rating_label]].values.ravel().tolist())) == 3:
palette = ['tomato', 'gold', 'limegreen']
# pp_cols = pp_cols[:5]
nrows = len(pp_cols)
fig = plt.figure(figsize=(figsize[0], figsize[1] * nrows))
# ncols = 2 * (nsites - 1) + 2
gs = GridSpec(nrows, 4, wspace=0.02)
gs.set_width_ratios([nsites, len(inputs), len(inputs), nsites])
for i, colname in enumerate(pp_cols):
ax_nzs = plt.subplot(gs[i, 0])
axg_nzs = plt.subplot(gs[i, 1])
axg_zsc = plt.subplot(gs[i, 2])
ax_zsc = plt.subplot(gs[i, 3])
# plots
sn.stripplot(x='site', y=colname, data=mdata, hue=rating_label, jitter=0.18, alpha=.6,
split=True, palette=palette, ax=ax_nzs)
sn.stripplot(x='site', y=colname, data=zscored, hue=rating_label, jitter=0.18, alpha=.6,
split=True, palette=palette, ax=ax_zsc)
sn.stripplot(x='database', y=colname, data=mdata, hue=rating_label, jitter=0.18, alpha=.6,
split=True, palette=palette, ax=axg_nzs)
sn.stripplot(x='database', y=colname, data=zscored, hue=rating_label, jitter=0.18,
alpha=.6, split=True, palette=palette, ax=axg_zsc)
ax_nzs.legend_.remove()
ax_zsc.legend_.remove()
axg_nzs.legend_.remove()
axg_zsc.legend_.remove()
if i == nrows - 1:
ax_nzs.set_xticklabels(ax_nzs.xaxis.get_majorticklabels(), rotation=80)
ax_zsc.set_xticklabels(ax_zsc.xaxis.get_majorticklabels(), rotation=80)
axg_nzs.set_xticklabels(axg_nzs.xaxis.get_majorticklabels(), rotation=80)
axg_zsc.set_xticklabels(axg_zsc.xaxis.get_majorticklabels(), rotation=80)
else:
ax_nzs.set_xticklabels([])
ax_zsc.set_xticklabels([])
axg_nzs.set_xticklabels([])
axg_zsc.set_xticklabels([])
ax_nzs.set_xlabel('', visible=False)
ax_zsc.set_xlabel('', visible=False)
ax_zsc.set_ylabel('', visible=False)
ax_zsc.yaxis.tick_right()
axg_nzs.set_yticklabels([])
axg_nzs.set_xlabel('', visible=False)
axg_nzs.set_ylabel('', visible=False)
axg_zsc.set_yticklabels([])
axg_zsc.set_xlabel('', visible=False)
axg_zsc.set_ylabel('', visible=False)
for yt in ax_nzs.yaxis.get_major_ticks()[1:-1]:
yt.label1.set_visible(False)
#.........这里部分代码省略.........