本文整理汇总了Python中seaborn.hls_palette方法的典型用法代码示例。如果您正苦于以下问题:Python seaborn.hls_palette方法的具体用法?Python seaborn.hls_palette怎么用?Python seaborn.hls_palette使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类seaborn
的用法示例。
在下文中一共展示了seaborn.hls_palette方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_labs_to_cmap
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import hls_palette [as 别名]
def test_labs_to_cmap():
sids = [0, 1, 2, 3, 4, 5, 6, 7]
labs = list(map(str, [3, 0, 1, 0, 0, 1, 2, 2]))
slab_csamples = eda.SingleLabelClassifiedSamples(
np.random.ranf(80).reshape(8, -1), labs, sids)
(lab_cmap, lab_norm, lab_ind_arr, lab_col_lut,
uniq_lab_lut) = eda.plot.labs_to_cmap(slab_csamples.labs, return_lut=True)
n_uniq_labs = len(set(labs))
assert lab_cmap.N == n_uniq_labs
assert lab_cmap.colors == sns.hls_palette(n_uniq_labs)
np.testing.assert_equal(
lab_ind_arr, np.array([3, 0, 1, 0, 0, 1, 2, 2]))
assert labs == [uniq_lab_lut[x] for x in lab_ind_arr]
assert len(uniq_lab_lut) == n_uniq_labs
assert len(lab_col_lut) == n_uniq_labs
assert [lab_col_lut[uniq_lab_lut[i]]
for i in range(n_uniq_labs)] == sns.hls_palette(n_uniq_labs)
lab_cmap2, lab_norm2 = eda.plot.labs_to_cmap(
slab_csamples.labs, return_lut=False)
assert lab_cmap2.N == n_uniq_labs
assert lab_cmap2.colors == lab_cmap.colors
np.testing.assert_equal(lab_norm2.boundaries, lab_norm.boundaries)
示例2: set_label_color
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import hls_palette [as 别名]
def set_label_color(nb_colors):
"""Set a color for each aggregated label with seaborn palettes
Parameters
----------
nb_colors : int
Number of label to display
"""
palette = sns.hls_palette(nb_colors, 0.01, 0.6, 0.75)
return ([int(255 * item) for item in color] for color in palette)
示例3: visualize_hist_pairplot
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import hls_palette [as 别名]
def visualize_hist_pairplot(X,y,selected_feature1,selected_feature2,features,diag_kind):
"""
Visualize the pairwise relationships (Histograms and Density Funcions) between classes and respective attributes
Keyword arguments:
X -- The feature vectors
y -- The target vector
selected_feature1 - First feature
selected_feature1 - Second feature
diag_kind -- Type of plot in the diagonal (Histogram or Density Function)
"""
#create data
joint_data=np.column_stack((X,y))
column_names=features
#create dataframe
df=pd.DataFrame(data=joint_data,columns=column_names)
#plot
palette = sea.hls_palette()
splot=sea.pairplot(df, hue="Y", palette={0:palette[2],1:palette[0]},vars=[selected_feature1,selected_feature2],diag_kind=diag_kind)
splot.fig.suptitle('Pairwise relationship: '+selected_feature1+" vs "+selected_feature2)
splot.set(xticklabels=[])
# plt.subplots_adjust(right=0.94, top=0.94)
#save fig
output_dir = "img"
save_fig(output_dir,'{}/{}_{}_hist_pairplot.png'.format(output_dir,selected_feature1,selected_feature2))
# plt.show()
示例4: visualize_feature_boxplot
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import hls_palette [as 别名]
def visualize_feature_boxplot(X,y,selected_feature,features):
"""
Visualize the boxplot of a feature
Keyword arguments:
X -- The feature vectors
y -- The target vector
selected_feature -- The desired feature to obtain the histogram
features -- Vector of feature names (X1 to XN)
"""
#create data
joint_data=np.column_stack((X,y))
column_names=features
#create dataframe
df=pd.DataFrame(data=joint_data,columns=column_names)
# palette = sea.hls_palette()
splot=sea.boxplot(data=df,x='Y',y=selected_feature,hue="Y",palette="husl")
plt.title('BoxPlot Distribution of '+selected_feature)
#save fig
output_dir = "img"
save_fig(output_dir,'{}/{}_boxplot.png'.format(output_dir,selected_feature))
# plt.show()
示例5: labs_to_cmap
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import hls_palette [as 别名]
def labs_to_cmap(labels, return_lut=False, shuffle_colors=False,
random_state=None):
np.random.seed(random_state)
# Each label has its own index and color
mtype.check_is_valid_labs(labels)
labels = np.array(labels)
uniq_lab_arr = np.unique(labels)
num_uniq_labs = len(uniq_lab_arr)
uniq_lab_inds = list(range(num_uniq_labs))
lab_col_list = list(sns.hls_palette(num_uniq_labs))
if shuffle_colors:
np.random.shuffle(lab_col_list)
lab_cmap = mpl.colors.ListedColormap(lab_col_list)
# Need to keep track the order of unique labels, so that a labeled
# legend can be generated.
# Map unique label indices to unique labels
uniq_lab_lut = dict(zip(range(num_uniq_labs), uniq_lab_arr))
# Map unique labels to indices
uniq_ind_lut = dict(zip(uniq_lab_arr, range(num_uniq_labs)))
# a list of label indices
lab_ind_arr = np.array([uniq_ind_lut[x] for x in labels])
# map unique labels to colors
# Used to generate legends
lab_col_lut = dict(zip([uniq_lab_lut[i]
for i in range(len(uniq_lab_arr))],
lab_col_list))
# norm separates cmap to difference indices
# https://matplotlib.org/tutorials/colors/colorbar_only.html
lab_norm = mpl.colors.BoundaryNorm(uniq_lab_inds + [lab_cmap.N],
lab_cmap.N)
if return_lut:
return lab_cmap, lab_norm, lab_ind_arr, lab_col_lut, uniq_lab_lut
else:
return lab_cmap, lab_norm
示例6: DrawScatters
# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import hls_palette [as 别名]
def DrawScatters(savefolder, annoFile, visMethod, cords, annos):
import plotly
import plotly.graph_objs as go
annText = os.path.basename(annoFile).split('.')[0]
for kind in ['cell type', 'top sample']:
if kind not in annos.columns:
continue
annotationList = sorted(list(set(annos.ix[:,kind])))
import seaborn as sns
colorList = sns.hls_palette(n_colors=len(annotationList))
data = []
annoLen = 0
for annoIdx in range(len(annotationList)):
annoNames = annotationList[annoIdx]
if len(annoNames) > annoLen:
annoLen = len(annoNames)
indicesOfAnno = annos[kind]==annoNames
text = []
for idx in annos.index[indicesOfAnno]:
show_text = '%s: %s, barcode: %s' % (kind, annoNames, idx)
text.append(show_text)
trace = go.Scatter(
x = cords.ix[annos.index[indicesOfAnno],'x'],
y = cords.ix[annos.index[indicesOfAnno],'y'],
name = annoNames,
mode = 'markers',
marker=dict(
color='rgb(%s, %s, %s)' % colorList[annoIdx],
size=5,
symbol='circle',
line=dict(
color='rgb(204, 204, 204)',
width=1
),
opacity=0.9
),
text = text,
)
data.append(trace)
if annoLen < 35:
layout = go.Layout(legend=dict(orientation="v"),autosize=True,showlegend=True)
else:
layout = go.Layout(legend=dict(orientation="v"),autosize=True,showlegend=False)
fig = go.Figure(data=data, layout=layout)
fn = os.path.join(savefolder, '%s_%s_%s.html' % (annText, kind.replace(' ', '_'), visMethod))
print('##########saving plot: %s' % fn)
plotly.offline.plot(fig, filename=fn)
#start to visualise test dataset