Python seaborn.hls_palette() Examples

The following are 6 code examples of seaborn.hls_palette(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module seaborn , or try the search function .
Example #1
Source File: test_plot.py    From scedar with MIT License 6 votes vote down vote up
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) 
Example #2
Source File: aggregate_label.py    From deeposlandia with MIT License 5 votes vote down vote up
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) 
Example #3
Source File: visualization.py    From default-credit-card-prediction with MIT License 5 votes vote down vote up
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() 
Example #4
Source File: visualization.py    From default-credit-card-prediction with MIT License 5 votes vote down vote up
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() 
Example #5
Source File: plot.py    From scedar with MIT License 5 votes vote down vote up
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 
Example #6
Source File: visAnnos.py    From scMatch with MIT License 4 votes vote down vote up
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