本文整理汇总了Python中seaborn.cubehelix_palette方法的典型用法代码示例。如果您正苦于以下问题:Python seaborn.cubehelix_palette方法的具体用法?Python seaborn.cubehelix_palette怎么用?Python seaborn.cubehelix_palette使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类seaborn
的用法示例。
在下文中一共展示了seaborn.cubehelix_palette方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_heatmap
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import cubehelix_palette [as 别名]
def plot_heatmap(outpath, df, sample_linkage, sample_colors, event_linkage, desc, sample_color_lut):
assert desc.lower().startswith('altsplice') or desc.lower().startswith('expression')
is_altsplice = desc.lower().startswith('altsplice')
sys.setrecursionlimit(100000)
print "Plotting data ... "
graph = sns.clustermap(df.T,
col_colors=sample_colors,
col_linkage=sample_linkage, row_linkage=event_linkage,
cmap = sns.cubehelix_palette(as_cmap=True))
graph.ax_heatmap.axis('off')
graph.ax_col_dendrogram.set_title("%s Clustering" %' '.join(desc.split('_')).title())
graph.ax_heatmap.set_xlabel("Events")
graph.ax_heatmap.set_ylabel("Samples")
if is_altsplice: graph.cax.set_title("psi")
else: graph.cax.set_title("log(counts)")
add_legend(graph, sample_color_lut)
plot_utils.save(outpath)
return
示例2: plot_heatmaps
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import cubehelix_palette [as 别名]
def plot_heatmaps(data, mis, column_label, cont, topk=30, prefix=''):
cmap = sns.cubehelix_palette(as_cmap=True, light=.9)
m, nv = mis.shape
for j in range(m):
inds = np.argsort(- mis[j, :])[:topk]
if len(inds) >= 2:
plt.clf()
order = np.argsort(cont[:,j])
subdata = data[:, inds][order].T
subdata -= np.nanmean(subdata, axis=1, keepdims=True)
subdata /= np.nanstd(subdata, axis=1, keepdims=True)
columns = [column_label[i] for i in inds]
sns.heatmap(subdata, vmin=-3, vmax=3, cmap=cmap, yticklabels=columns, xticklabels=False, mask=np.isnan(subdata))
filename = '{}/heatmaps/group_num={}.png'.format(prefix, j)
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
plt.title("Latent factor {}".format(j))
plt.yticks(rotation=0)
plt.savefig(filename, bbox_inches='tight')
plt.close('all')
#plot_rels(data[:, inds], map(lambda q: column_label[q], inds), colors=cont[:, j],
# outfile=prefix + '/relationships/group_num=' + str(j), latent=labels[:, j], alpha=0.1)
示例3: _parse_heatmap_metadata_annotations
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import cubehelix_palette [as 别名]
def _parse_heatmap_metadata_annotations(metadata_column, margin_palette):
'''
Transform feature or sample metadata into color vector for annotating
margin of clustermap.
Parameters
----------
metadata_column: pd.Series of metadata for annotating plots
margin_palette: str
Name of color palette to use for annotating metadata
along margin(s) of clustermap.
Returns
-------
Returns vector of colors for annotating clustermap and dict mapping colors
to classes.
'''
# Create a categorical palette to identify md col
metadata_column = metadata_column.astype(str)
col_names = sorted(metadata_column.unique())
# Select Color palette
if margin_palette == 'colorhelix':
col_palette = sns.cubehelix_palette(
len(col_names), start=2, rot=3, dark=0.3, light=0.8, reverse=True)
else:
col_palette = sns.color_palette(margin_palette, len(col_names))
class_colors = dict(zip(col_names, col_palette))
# Convert the palette to vectors that will be drawn on the matrix margin
col_colors = metadata_column.map(class_colors)
return col_colors, class_colors
示例4: plot_heatmaps
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import cubehelix_palette [as 别名]
def plot_heatmaps(data, alpha, mis, column_label, cont, topk=40, athresh=0.2, prefix=''):
import seaborn as sns
cmap = sns.cubehelix_palette(as_cmap=True, light=.9)
import matplotlib.pyplot as plt
m, nv = mis.shape
for j in range(m):
inds = np.where(np.logical_and(alpha[j] > athresh, mis[j] > 0.))[0]
inds = inds[np.argsort(- alpha[j, inds] * mis[j, inds])][:topk]
if len(inds) >= 2:
plt.clf()
order = np.argsort(cont[:,j])
if type(data) == np.ndarray:
subdata = data[:, inds][order].T
else:
# assume sparse
subdata = data[:, inds].toarray()
subdata = subdata[order].T
columns = [column_label[i] for i in inds]
fig, ax = plt.subplots(figsize=(20, 10))
sns.heatmap(subdata, vmin=0, vmax=1, cmap=cmap, yticklabels=columns, xticklabels=False, ax=ax, cbar_kws={"ticks": [0, 0.5, 1]})
plt.yticks(rotation=0)
filename = '{}/heatmaps/group_num={}.png'.format(prefix, j)
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
plt.title("Latent factor {}".format(j))
plt.savefig(filename, bbox_inches='tight')
plt.close('all')
#plot_rels(data[:, inds], map(lambda q: column_label[q], inds), colors=cont[:, j],
# outfile=prefix + '/relationships/group_num=' + str(j), latent=labels[:, j], alpha=0.1)
示例5: get_colorbar
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import cubehelix_palette [as 别名]
def get_colorbar(dfr, classes):
"""Return a colorbar representing classes, for a Seaborn plot.
:param dfr:
:param classes:
The aim is to get a pd.Series for the passed dataframe columns,
in the form:
0 colour for class in col 0
1 colour for class in col 1
... colour for class in col ...
n colour for class in col n
"""
levels = sorted(list(set(classes.values())))
paldict = dict(
zip(
levels,
sns.cubehelix_palette(
len(levels), light=0.9, dark=0.1, reverse=True, start=1, rot=-2
),
)
)
lvl_pal = {cls: paldict[lvl] for (cls, lvl) in list(classes.items())}
# Have to use string conversion of the dataframe index, here
col_cb = pd.Series([str(_) for _ in dfr.index]).map(lvl_pal)
# The col_cb Series index now has to match the dfr.index, but
# we don't create the Series with this (and if we try, it
# fails) - so change it with this line
col_cb.index = dfr.index
return col_cb
# Add labels to the seaborn heatmap axes
示例6: plot_heatmaps
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import cubehelix_palette [as 别名]
def plot_heatmaps(data, labels, alpha, mis, column_label, cont, topk=20, prefix='', focus=''):
cmap = sns.cubehelix_palette(as_cmap=True, light=.9)
m, nv = mis.shape
for j in range(m):
inds = np.where(np.logical_and(alpha[j] > 0, mis[j] > 0.))[0]
inds = inds[np.argsort(- alpha[j, inds] * mis[j, inds])][:topk]
if focus in column_label:
ifocus = column_label.index(focus)
if not ifocus in inds:
inds = np.insert(inds, 0, ifocus)
if len(inds) >= 2:
plt.clf()
order = np.argsort(cont[:,j])
subdata = data[:, inds][order].T
subdata -= np.nanmean(subdata, axis=1, keepdims=True)
subdata /= np.nanstd(subdata, axis=1, keepdims=True)
columns = [column_label[i] for i in inds]
sns.heatmap(subdata, vmin=-3, vmax=3, cmap=cmap, yticklabels=columns, xticklabels=False, mask=np.isnan(subdata))
filename = '{}/heatmaps/group_num={}.png'.format(prefix, j)
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
plt.title("Latent factor {}".format(j))
plt.savefig(filename, bbox_inches='tight')
plt.close('all')
#plot_rels(data[:, inds], list(map(lambda q: column_label[q], inds)), colors=cont[:, j],
# outfile=prefix + '/relationships/group_num=' + str(j), latent=labels[:, j], alpha=0.1)
示例7: plot_pairplots
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import cubehelix_palette [as 别名]
def plot_pairplots(data, labels, alpha, mis, column_label, topk=5, prefix='', focus=''):
cmap = sns.cubehelix_palette(as_cmap=True, light=.9)
plt.rcParams.update({'font.size': 32})
m, nv = mis.shape
for j in range(m):
inds = np.where(np.logical_and(alpha[j] > 0, mis[j] > 0.))[0]
inds = inds[np.argsort(- alpha[j, inds] * mis[j, inds])][:topk]
if focus in column_label:
ifocus = column_label.index(focus)
if not ifocus in inds:
inds = np.insert(inds, 0, ifocus)
if len(inds) >= 2:
plt.clf()
subdata = data[:, inds]
columns = [column_label[i] for i in inds]
subdata = pd.DataFrame(data=subdata, columns=columns)
try:
sns.pairplot(subdata, kind="reg", diag_kind="kde", height=5, dropna=True)
filename = '{}/pairplots_regress/group_num={}.pdf'.format(prefix, j)
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
plt.suptitle("Latent factor {}".format(j), y=1.01)
plt.savefig(filename, bbox_inches='tight')
plt.clf()
except:
pass
subdata['Latent factor'] = labels[:,j]
try:
sns.pairplot(subdata, kind="scatter", dropna=True, vars=subdata.columns.drop('Latent factor'), hue="Latent factor", diag_kind="kde", height=5)
filename = '{}/pairplots/group_num={}.pdf'.format(prefix, j)
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
plt.suptitle("Latent factor {}".format(j), y=1.01)
plt.savefig(filename, bbox_inches='tight')
plt.close('all')
except:
pass