Beispiel #1
0
def cmap_builder(name, name2=None, name3=None):
    """return a colormap object compatible with matplotlib

    If only parameter **name** is provided, it should be a known matplotlib 
    colormap name (e.g., jet). If **name2** is provided, then a new colormap 
    is created going from the color **name** to the color **name2** with a
    linear scale. Finally, if **name3** is provided, a linear scaled colormap
    is built from color **name** to color **name3** with the intermediate color
    being the **name2**

    Matplotlib colormap map names


    """
    c = Colormap()
    # an R colormap
    if name and name2 and name3:
        return c.cmap_linear(name, name2, name3)
    elif name and name2:
        return c.cmap_bicolor(name, name2)
    elif name == 'heat':
        return c.get_cmap_heat()
    elif name == 'heat_r':
        return c.get_cmap_heat_r()
    # matplotlic colormaps
    elif name in c.colormaps:
        return c.cmap(name)
    # some custom diverging colormaps with black in the middle.
    elif name in c.diverging_black:
        return c.cmap(name)
    else:
        #valid = c.colormaps + c.diverging_black
        txt = "name provided {0} is not recognised. ".format(name)
        txt += "\n valid name can be found in colormap.colormap_names"
        raise ValueError(txt)
Beispiel #2
0
 def get_colors(self, sequencial):
     c = Colormap()
     if sequencial:
         mycmap = c.cmap('YlGnBu')
     else:
         mycmap = c.cmap('tab10')
     rgba = mycmap(np.linspace(0, 1, 256)) * 255
     long = len(rgba)
     return rgba, long
Beispiel #3
0
def _plot_HiC(matrix_data, vmax, colors=['white', 'red']):
    #vmax=thr
    red_list = list()
    green_list = list()
    blue_list = list()
    #colors=['white','red']
    #colors=['darkblue','green','gold','darkred']
    for color in colors:
        col = Color(color).rgb
        red_list.append(col[0])
        green_list.append(col[1])
        blue_list.append(col[2])
    c = Colormap()
    d = {'blue': blue_list, 'green': green_list, 'red': red_list}
    mycmap = c.cmap(d)
    fig, ax = plt.subplots(figsize=(8, 8))
    #new_data=np.triu(matrix_data)
    #new_data=np.transpose(new_data[:,::-1])
    #mask = np.zeros_like(new_data)
    #mask[np.tril_indices_from(mask,-1)] = True
    #mask=np.transpose(mask[:,::-1])
    #with sns.axes_style("white"):
    #sns.heatmap(new_data,xticklabels=100,yticklabels=100,mask=mask,cmap=mycmap,cbar=False)
    #ax.set_facecolor('w')
    #fig.patch.set_facecolor('w')
    ax.set_facecolor('w')
    ax.grid(b=None)
    sns.heatmap(matrix_data.T,
                vmax=vmax,
                xticklabels=100,
                yticklabels=100,
                cmap=mycmap,
                cbar=False)
Beispiel #4
0
def cmap_builder(name, name2=None, name3=None):
    """return a colormap object compatible with matplotlib

    If only parameter **name** is provided, it should be a known matplotlib 
    colormap name (e.g., jet). If **name2** is provided, then a new colormap 
    is created going from the color **name** to the color **name2** with a
    linear scale. Finally, if **name3** is provided, a linear scaled colormap
    is built from color **name** to color **name3** with the intermediate color
    being the **name2**

    Matplotlib colormap map names

    """
    c = Colormap()
    # an R colormap
    if name and name2 and name3:
        return c.cmap_linear(name, name2, name3)
    elif name and name2:
        return c.cmap_bicolor(name, name2)
    elif name == 'heat':
        return c.get_cmap_heat()
    elif name == 'heat_r':
        return c.get_cmap_heat_r()
    # matplotlic colormaps
    elif name in c.colormaps:
        return c.cmap(name)
    # some custom diverging colormaps with black in the middle.
    elif name in c.diverging_black:
        return c.cmap(name)
    elif name.count("_") == 2:
        name1, name2, name3 = name.split("_")
        return c.cmap_linear(name1, name2, name3)
    else:
        #valid = c.colormaps + c.diverging_black
        txt = "name provided {0} is not recognised. ".format(name)
        txt += "\n valid name can be found in colormap.colormap_names"
        raise ValueError(txt)
Beispiel #5
0
def _show_chic_clusterresult3(Results,
                              matrix_data,
                              colors=['white', 'green', 'blue', 'red']):
    if np.max(matrix_data.shape) < 3000:
        thr = np.percentile(matrix_data, 99.5)
    else:
        thr = np.percentile(matrix_data, 99.9)
    matrix_data[matrix_data > thr] = thr
    print(thr)
    red_list = list()
    green_list = list()
    blue_list = list()
    #['darkblue','seagreen','yellow','gold','coral','hotpink','red']
    for color in colors:
        col = Color(color).rgb
        red_list.append(col[0])
        green_list.append(col[1])
        blue_list.append(col[2])
    c = Colormap()
    d = {'blue': blue_list, 'green': green_list, 'red': red_list}
    mycmap = c.cmap(d)
    #plt.subplots(figsize=(8,8))
    #sns.heatmap(np.transpose(matrix_data[:,::-1]),cmap=mycmap)
    #sns.heatmap(np.transpose(matrix_data[:,::-1]),xticklabels=100,yticklabels=500,cmap=mycmap)
    plt.subplots(figsize=(8, 8))

    #sns.heatmap(np.transpose(matrix_data[:,::-1]),cmap=mycmap)

    #sns.heatmap(np.transpose(matrix_data[:,::-1]),xticklabels=100,yticklabels=500,cmap=mycmap,cbar=False)
    sns.heatmap(matrix_data.T,
                xticklabels=100,
                yticklabels=1000,
                cmap=mycmap,
                cbar=False)

    for i in Results.index:
        upper = Results.ix[i, 'upper']
        bottom = Results.ix[i, 'bottom']
        left = Results.ix[i, 'left']
        right = Results.ix[i, 'right']
        x_loc = [upper, upper, bottom, bottom, upper]
        y_loc = [left, right, right, left, left]
        plt.plot(x_loc, y_loc, '-', color='k', lw=2.5)
    plt.grid(b=None)
    plt.show()