Esempio n. 1
0
def draw_holoviews_graphs(graph_dict):
    # use first key to determine default settings
    first_key = list(graph_dict.keys())[0]
    molecule, ksize, log2sketchsize = first_key

    hv.extension('bokeh')
    defaults = dict(width=400, height=400, padding=0.1)
    hv.opts.defaults(opts.EdgePaths(**defaults), opts.Graph(**defaults),
                     opts.Nodes(**defaults))

    kdims = [
        hv.Dimension(('molecule', "molecule"), default=molecule),
        hv.Dimension(('ksize', "k-mer size"), default=ksize),
        hv.Dimension(('log2_num_hashes', "$\log_2$ num hashes"),
                     default=log2sketchsize),
    ]

    kwargs = dict(width=800, height=800, xaxis=None, yaxis=None)
    opts.defaults(opts.Nodes(**kwargs), opts.Graph(**kwargs))

    kwargs = dict(node_size=10,
                  edge_line_width=1,
                  cmap='Set2',
                  node_color=dim("species"),
                  node_line_color='gray',
                  width=600,
                  height=600,
                  xaxis=None,
                  yaxis=None)

    holomap = hv.HoloMap(graph_dict, kdims=kdims)
    holomap.opts(opts.Graph(**kwargs))
    return holomap
Esempio n. 2
0
def draw_graph(G, label, cmap):
    print(f'Shading {label}')
    shaded = (datashade(G, normalization='linear', width=1000, height=1000) *
              G.nodes).opts(
                  opts.Nodes(color=label,
                             width=1000,
                             cmap=cmap,
                             legend_position='right'))

    hv.save(shaded, f'graphs/png/{label}.png')
    hv.save(shaded, f'graphs/html/{label}.html')
Esempio n. 3
0
    def view_network(self):
        if self.mapdf is None:
            return pn.indicators.LoadingSpinner(value=True,
                                                width=100,
                                                height=100)
        G = get_graph(self.model_path)
        if G.order == 0:
            return pn.pane.Alert(
                f'## No network file found on {self.model_path}')
        nodeloc = list(
            filter(lambda n: n[1]['name'] == self.localities,
                   G.nodes(data=True)))
        # print(nodeloc, self.localities)
        if nodeloc == []:
            return pn.pane.Alert(f'## Please select a locality.')
        H = get_subgraph(G, nodeloc[0][0])
        partial_map = self.mapdf[self.mapdf.geocode.isin(H.nodes)]
        partial_map = partial_map.set_crs(4326)
        partial_map = partial_map.to_crs(3857)  # Converting to web mercator
        centroids = [(c.x, c.y) for c in partial_map.centroid]
        # Draw the graph using Altair
        gcs = [int(gc) for gc in partial_map.geocode]
        pos = dict(zip(gcs, centroids))

        # viz = nxa.draw_networkx(
        #     G, pos=pos,
        #     node_color='weight',
        #     cmap='viridis',
        #     width='weight',
        #     edge_color='black',
        # )

        kwargs = dict(width=800, height=800, xaxis=None, yaxis=None)
        hv.opts.defaults(opts.Nodes(**kwargs), opts.Graph(**kwargs))
        colors = ['#000000'] + hv.Cycle('Category20').values
        epi_graph = hv.Graph.from_networkx(H, positions=pos)

        epi_graph.opts(cmap=colors,
                       node_size=10,
                       edge_line_width=1,
                       directed=True,
                       node_line_color='gray',
                       edge_color='gray',
                       node_color='circle')
        tiles = gv.tile_sources.Wikipedia

        f = bundle_graph(epi_graph) * tiles
        source = epi_graph.nodes.clone()
        # print(epi_graph.nodes.data.iloc[0])
        source.data = epi_graph.nodes.data[epi_graph.nodes.data.name ==
                                           self.localities]

        return f * source.opts(color='red')
Esempio n. 4
0
def generateGraph():
    df = processCSVMatrix(file)
    names = df.columns
    # submatrix for quicker development
    if (len(names) > 150):
        df = df.head(150)[names[0:150]]
    # set defaults for HoloViews
    extension('bokeh')
    renderer('bokeh').webgl = True
    defaults = dict(width=400, height=400, padding=0.1)
    opts.defaults(opts.EdgePaths(**defaults), opts.Graph(**defaults),
                  opts.Nodes(**defaults))

    G = from_pandas_adjacency(df)
    graph = Graph.from_networkx(G,
                                circular_layout).opts(directed=False,
                                                      width=600,
                                                      height=600,
                                                      arrowhead_length=0.0005)
    # Make a panel and widgets with param for choosing a layout
    return pn.Column(graph)
Esempio n. 5
0
# Now we switch to holoviews to render the plot
# Specify the plot render to use
hv.extension('bokeh')
hv.output(size=300)

# Chord diagram with interactive components
edgeList = edges[['Source', 'Target', 'weight']]
# Within the holoviews dataset object we define kdim and vdims
# Kdims are the independent variables which is Id in this example
# Vdims are dependent variables cent_value and rank_value
# By defining these here were can use them when creating the graph
nodeDS = hv.Dataset(nodes_extended, 'Id', ['cent_value', 'rank_value'])

# Coloured interactive chord diagram with node size determined by Vdims
kwargs = dict(width=300, height=300, xaxis=None, yaxis=None)
opts.defaults(opts.Nodes(**kwargs), opts.Graph(**kwargs))

graph = hv.Graph((edgeList, nodeDS), label='GoT season 1')
graph.opts(cmap='Category20',
           edge_cmap='Category20',
           node_size='cent_value',
           edge_line_width=1,
           node_color=dim('Id').str(),
           edge_color=dim('Source').str())
graph.opts(
    opts.Chord(inspection_policy='nodes',
               tools=['hover'],
               edge_hover_line_color='green',
               node_hover_fill_color='red'))

hv.save(graph, 'node_size_chord.html')
from bokeh.transform import linear_cmap, factor_cmap
from bokeh.palettes import Spectral6
from bokeh.layouts import row, column
from bokeh.models import CustomJS, Slider
import networkx as nx
import numpy as np
import matplotlib.image as mpimg
from IPython.display import Image
import matplotlib.pyplot as plt
import holoviews as hv
from holoviews import opts
hv.extension('bokeh')

defaults = dict(width=400, height=400, padding=0.1)
hv.opts.defaults(opts.EdgePaths(**defaults), opts.Graph(**defaults),
                 opts.Nodes(**defaults))

output_file("bokeh_testing.html")

nodes = [
    {
        "id": 1,
        "type": "Resevoir",
        "edges": [2, 3],
        "demand": [2, 4, 6, 5],
        "pol": [1, 2, 3, 4]
    },
    {
        "id": 2,
        "type": "Tank",
        "edges": [1, 3],