コード例 #1
0
def makeHoverCarpet(carpets, collabels, rowlabels, maxval, extralabels):
    """
    makes a 3 carpet heatmap
    """
    if (len(rowlabels) < 1):
        print('no wells to show')
        return
    hv.extension('bokeh', width=90)
    sprowlabels = [
        rowlabels[i] + ',' + extralabels[i] for i in range(len(rowlabels))
    ]
    heatmap1 = hv.HeatMap(
        (collabels, sprowlabels, carpets[0])).opts(title=targets[0] + ' dRn')
    heatmap2 = hv.HeatMap(
        (collabels, sprowlabels, carpets[1])).opts(title=targets[1] + ' dRn')
    heatmap3 = hv.HeatMap(
        (collabels, sprowlabels, carpets[2])).opts(title=targets[2] + ' dRn')
    tooltips = [('Well', '@y'), ('Cycle', '@x'), ('dRn', '@z')]
    hover = HoverTool(tooltips=tooltips)
    layout = heatmap1 + heatmap2 + heatmap3
    layout.opts(
        opts.HeatMap(tools=[hover],
                     cmap='jet',
                     colorbar=True,
                     invert_yaxis=True,
                     clim=(0.0, maxval),
                     width=400,
                     height=800,
                     xlabel='Cycle',
                     ylabel='Wells'))
    return layout
コード例 #2
0
ファイル: graph.py プロジェクト: JonETJakobsson/scConnect
def plot_adjacency_matrix(G,
                          save=False,
                          filename=None,
                          weight="weighted_score",
                          log=False,
                          width=200,
                          height=200,
                          fontsize=10,
                          fontscale=1.5):
    """Flattens and plots an adjecency matric for a given graph.
    If a split graph is provided, plots adjacency matrix for each interaction.

    Weight can be "weighted_score" or "score".
    Returns: Holoviews heatmap
    """
    import numpy as np
    import holoviews as hv
    from holoviews import opts
    import networkx as nx
    hv.extension('bokeh')

    # Create adjecency matrix and sort index and columns by name
    matrix = nx.to_pandas_adjacency(G, weight=weight)

    if log:
        matrix = np.log10(matrix)

    matrix = matrix.sort_index(ascending=True)
    matrix = matrix[matrix.index.values]
    matrix = matrix.stack()
    matrix = matrix.reset_index(name="values")
    matrix.columns = ["source", "target", "values"]

    # Plot the matrix as a heatmap
    heatmap = hv.HeatMap(matrix, kdims=["target", "source"])

    # Rotate X lables and show the color bar
    heatmap.opts(
        opts.HeatMap(tools=["hover"],
                     xrotation=90,
                     colorbar=True,
                     width=width,
                     height=height,
                     fontsize=fontsize,
                     fontscale=fontscale))

    if save is True:
        hv.save(heatmap, filename)
    return heatmap
コード例 #3
0
ファイル: common.py プロジェクト: aehrc/COVID19_TBED
def setLibrary(library='bokeh'):
    ## Use Bokeh by default
    if (library == 'bokeh'):
        hv.extension('bokeh')
        hv.archive.auto(filename_formatter="{obj:.7}")  ## For notebooks

        opts.defaults(
            opts.Scatter(tools=['hover'], width=700, height=700, padding=0.05),
            opts.HeatMap(tools=['hover'],
                         width=700,
                         height=700,
                         labelled=[],
                         xrotation=45,
                         colorbar=True,
                         cmap=('Blues')))

        #     opts.HeatMap(tools=['hover'], width=700, height=700, labelled=[],
        #                  xrotation=45, colorbar=True, cmap=('Blues')))

        ## The library that Bokeh uses to export to SVG is not longer supported
        ## and so cannot be exported to SVG

    elif (library == 'matplotlib'):
        hv.extension('matplotlib')
        hv.output(fig='svg')

        opts.defaults(
            opts.Scatter(fig_size=300, padding=0.05),
            opts.HeatMap(fig_size=300,
                         labelled=[],
                         xrotation=45,
                         colorbar=True,
                         cmap=('Blues')))

    else:
        raise NotImplementedError("Unknown plotting library.")
コード例 #4
0
 def get_heatmap(data,
                 lim,
                 title,
                 kdim='x',
                 vdim='Iteration',
                 height=200):
     return hv.HeatMap(data, kdims=[kdim, vdim]).opts(
         opts.HeatMap(tools=['hover'],
                      colorbar=True,
                      width=350,
                      height=height,
                      invert_yaxis=True,
                      ylabel='Iteration',
                      title=title,
                      clim=(-lim, lim),
                      cmap='RdBu'))
コード例 #5
0
def plot_connectivity_matrix(connectivity_matrix,
                             atlas_labels,
                             threshold=None,
                             dst_dir=None,
                             filename=None):
    '''Plot a connectivity matrix. This function is very similar to nilearn.plotting.plot_matrix
    but uses the bokeh backend and is therefore interactive
    
    Parameters
    ----------
    connectivity_matrix : np.array
        A symmetric connectivity matrix.
    atlas_labels : pd.Series or list
        A list-like object providing names of each atlas region.
    threshold : float or int, optional
        Apply a threshold to the connectivity matrix before plotting. Values 
        lower than this threshold will be set to 0.
    dst_dir : str, optional
        Name of the output directory. The default is None.
    filename : str, optional
        Name of the file (must be provided including the extenstion). 
        The default is None.


    Returns
    -------
    connectogram_plot : holoviews.element.raster.HeatMap
        The the connectivity matrix plot object.


    '''

    # copy matrix
    connectivity_matrix = connectivity_matrix.copy()

    # convert to pd.DataFrame for further processing
    connectivity_matrix_df = pd.DataFrame(data=connectivity_matrix,
                                          columns=atlas_labels,
                                          index=atlas_labels)

    # Ensure that index name has the default name 'Index'
    if connectivity_matrix_df.index.name:
        connectivity_matrix_df.index.name = None

    # stack connectivity_matrix
    connectivity_matrix_stacked = connectivity_matrix_df.stack().reset_index()
    connectivity_matrix_stacked.columns = ['source', 'target', 'value']

    if threshold:
        connectivity_matrix_stacked['value'].where(
            connectivity_matrix_stacked['value'] >= threshold, 0, inplace=True)

    connectivity_matrix_stacked_ds = hv.Dataset(connectivity_matrix_stacked,
                                                ['source', 'target'])
    heatmap = hv.HeatMap(connectivity_matrix_stacked_ds)
    heatmap.opts(
        opts.HeatMap(tools=['hover'],
                     colorbar=True,
                     xaxis='bare',
                     yaxis='bare',
                     cmap='blues_r'))

    # save plot
    if dst_dir:
        if not filename:
            raise ValueError('Please provide a filename')

        dst_path = dst_dir + filename
        hv.save(heatmap, dst_path)

    # FIXME: this doesn't work for me in Spyder
    show(hv.render(heatmap))

    return heatmap
コード例 #6
0
from holoviews import opts
import panel as pn
import altair as alt
from altair import datum

pn.extension('vega')
#alt.renderers.enable('altair_viewer')
alt.data_transformers.disable_max_rows()
hv.extension("bokeh")
medal_count_year_withCate = pd.read_csv("medal_count_year_withCate.csv")
medal_count_year_top10 = medal_count_year_withCate.loc[medal_count_year_withCate["Order"]<=10]

year_unique = medal_count_year_top10["Year"].unique().tolist()
name_unique = medal_count_year_top10["name"].unique().tolist()
heatmap = hv.HeatMap(medal_count_year_top10, ["Year", "name"],["Medal"])
heatmap.opts(opts.HeatMap(radial=True,colorbar=True, start_angle=np.pi/2, width=500, height=500,
    yticks=None,xticks=year_unique,tools=['hover'],toolbar='above'))

slider_year = alt.binding_range(min=1896, max=2016, step=4, name='Year:')
selector_year = alt.selection_single(fields=['Year'],bind=slider_year, init={'Year': 2016})
select_country = alt.selection(type="single", fields=['Year'])

olympic_bar = alt.Chart(medal_count_year_withCate).mark_bar(opacity=0.8).encode(
    x=alt.X(field="name", type='nominal', title="country",sort = '-y',
            axis=alt.Axis(labelFontSize=10,titleFontSize=15,labelAngle=-45)),
    y=alt.Y(field="MedalByCate",type="quantitative",aggregate='sum',stack='zero',title="Total Medals",
            axis=alt.Axis(labelFontSize=10,titleFontSize=15)),
    color=alt.Color(field = 'MedalCate', type = 'nominal',
                    scale = alt.Scale(domain = ["Gold","Silver","Bronze"],range=['gold', 'silver','sienna']),
                    legend=alt.Legend(title="Medal Category",labelFontSize = 15,symbolSize = 30,titleFontSize=10)),
    order=alt.Order('MedalCateOrder',sort='ascending')
)
コード例 #7
0
            edge_color='Gender',
            edge_line_width=0,
            node_alpha=1.0,
            node_width=40,
            node_sort=True,
            width=1000,
            height=800,
            bgcolor="snow",
            title="Distribution of the population of people with a dry cough")
#show(hv.render(sankey))
heatmap = hv.HeatMap(sym_fin,
                     vdims=['Dry.Cough']).sort().aggregate(function=np.sum)
heatmap.opts(
    opts.HeatMap(tools=['hover'],
                 colorbar=True,
                 width=400,
                 height=500,
                 toolbar='above'))

#hv_ds = hv.Dataset(data=sym_fin, kdims=["Age", "Gender"], vdims=['Difficulty.in.Breathing'])
#sankey.data=hv_ds.data
#hv_ds.to(hv.Sankey)

hv_ds = hv.Dataset(data=sym_fin,
                   kdims=["Age", "Gender"],
                   vdims=['Difficulty.in.Breathing'])
sankey2 = hv_ds.to(hv.Sankey)
sankey2.opts(
    cmap='Colorblind',
    label_position='left',
    edge_color='Gender',