Beispiel #1
0
def test_graphrenderer_check_malformed_graph_source_no_node_index():
    node_source = ColumnDataSource()
    node_renderer = GlyphRenderer(data_source=node_source, glyph=Circle())
    renderer = GraphRenderer(node_renderer=node_renderer)

    check = renderer._check_malformed_graph_source()
    assert check != []
Beispiel #2
0
def test_graphrenderer_check_malformed_graph_source_no_edge_start_or_end():
    edge_source = ColumnDataSource()
    edge_renderer = GlyphRenderer(data_source=edge_source, glyph=MultiLine())
    renderer = GraphRenderer(edge_renderer=edge_renderer)

    check = renderer._check_malformed_graph_source()
    assert check != []
Beispiel #3
0
    def build_renderers(self):
        """Yields all renderers that make up the BoxGlyph."""

        self.calc_quartiles()
        outlier_values = self.values[((self.values < self.w0) |
                                      (self.values > self.w1))]

        self.whisker_glyph = GlyphRenderer(
            glyph=Segment(x0='x0s',
                          y0='y0s',
                          x1='x1s',
                          y1='y1s',
                          line_width=self.whisker_line_width,
                          line_color=self.whisker_color))

        if len(outlier_values) > 0 and self.outliers:
            self.outliers = PointGlyph(label=self.label,
                                       y=outlier_values,
                                       x=[self.get_dodge_label()] *
                                       len(outlier_values),
                                       line_color=self.outlier_line_color,
                                       fill_color=self.outlier_fill_color,
                                       size=self.outlier_size,
                                       marker=self.marker)

        for comp_glyph in self.composite_glyphs:
            for renderer in comp_glyph.renderers:
                yield renderer

        yield self.whisker_glyph
Beispiel #4
0
 def build_renderers(self):
     glyph = Rect(x='x',
                  y='y',
                  width='width',
                  height='height',
                  fill_color='color',
                  fill_alpha='fill_alpha')
     yield GlyphRenderer(glyph=glyph)
Beispiel #5
0
 def build_renderers(self):
     """Yield a `GlyphRenderer` for the group of data."""
     glyph = Line(x='x_values', y='y_values',
                  line_color=self.line_color,
                  line_alpha=self.line_alpha,
                  line_width=self.width,
                  line_dash=self.dash)
     yield GlyphRenderer(glyph=glyph)
Beispiel #6
0
 def build_renderers(self):
     glyph = Line(x='x_values',
                  y='y_values',
                  line_color=self.line_color,
                  line_alpha=self.line_alpha,
                  line_width=self.width,
                  line_dash=self.dash)
     yield GlyphRenderer(glyph=glyph)
Beispiel #7
0
    def __init__(self,
                 car_width=0.1,
                 car_height=0.05,
                 rod_length=0.5,
                 pendulum_size=0.05):
        self.car_width = car_width
        self.car_height = car_height

        self.rod_length = rod_length
        self.pendulum_size = pendulum_size

        self.pendulum = GlyphRenderer(data_source=ColumnDataSource(
            dict(x=[0], y=[0])),
                                      glyph=Ellipse(x='x',
                                                    y='y',
                                                    width=self.pendulum_size,
                                                    height=self.pendulum_size))

        self.car = GlyphRenderer(data_source=ColumnDataSource(
            dict(x=[0], y=[0])),
                                 glyph=Rect(x='x',
                                            y='y',
                                            width=self.car_width,
                                            height=self.car_height))

        self.rod = GlyphRenderer(data_source=ColumnDataSource(
            dict(x=[0, 0], y=[0, 0])),
                                 glyph=Line(x='x', y='y', line_width=2))

        self.move = GlyphRenderer(data_source=ColumnDataSource(
            dict(x=deque([0, 1], maxlen=200), y=deque([0, 1], maxlen=200))),
                                  glyph=Ellipse(x='x',
                                                y='y',
                                                width=0.008,
                                                height=0.008,
                                                fill_alpha=0.25,
                                                line_alpha=0.0,
                                                fill_color="#cc0000"))

        self.ground = GlyphRenderer(data_source=ColumnDataSource(
            dict(x=[-100, 100], y=[-car_height / 2, -car_height / 2])),
                                    glyph=Line(x='x',
                                               y='y',
                                               line_width=1,
                                               line_alpha=0.5))
Beispiel #8
0
    def build_renderers(self):
        if self.stem:
            yield GlyphRenderer(glyph=Segment(
                x0='x', y0=0, x1='x', y1='height',
                line_width=self.stem_line_width,
                line_color=self.stem_color,
                line_alpha='fill_alpha')
            )

        glyph_type = self.get_glyph()
        glyph = glyph_type(x='x', y='height',
                           line_color=self.line_color,
                           fill_color=self.color,
                           size=self.size,
                           fill_alpha='fill_alpha',
                           line_alpha='line_alpha'
                           )
        yield GlyphRenderer(glyph=glyph)
Beispiel #9
0
 def build_renderers(self):
     glyph_type = self.get_glyph()
     glyph = glyph_type(x='x_values', y='y_values',
                        line_color=self.line_color,
                        fill_color=self.fill_color,
                        size=self.size,
                        fill_alpha=self.fill_alpha,
                        line_alpha=self.line_alpha)
     yield GlyphRenderer(glyph=glyph)
Beispiel #10
0
 def build_renderers(self):
     """Yield a `GlyphRenderer` for the group of data."""
     glyph = Arc(x='x',
                 y='y',
                 radius=1,
                 start_angle='_end_angle',
                 end_angle='_start_angle',
                 line_color='line_color')
     yield GlyphRenderer(glyph=glyph)
    def yield_renderers(self):
        """Use the marker glyphs to display the arcs and beziers.
        Takes reference points from data loaded at the ColumnDataSource.
        """
        beziers = Bezier(x0='start_x',
                         y0='start_y',
                         x1='end_x',
                         y1='end_y',
                         cx0='cx0',
                         cy0='cy0',
                         cx1='cx1',
                         cy1='cy1',
                         line_alpha='weight',
                         line_color='colors')

        yield GlyphRenderer(data_source=self.connection_data, glyph=beziers)

        arcs = Arc(x=0,
                   y=0,
                   radius=1,
                   line_width=10,
                   start_angle='start_angle',
                   end_angle='end_angle',
                   line_color='line_color')

        yield GlyphRenderer(data_source=self.arcs_data, glyph=arcs)

        if self.label:

            text_props = {
                "text_color": "#000000",
                "text_font_size": "8pt",
                "text_align": "left",
                "text_baseline": "middle"
            }

            labels = Text(x='text_x',
                          y='text_y',
                          text='text',
                          angle='angles',
                          **text_props
                          )

            yield GlyphRenderer(data_source=self.text_data, glyph=labels)
Beispiel #12
0
 def build_renderers(self):
     """Yields a `GlyphRenderer` associated with a `Rect` glyph."""
     glyph = Rect(x='x',
                  y='y',
                  width='width',
                  height='height',
                  fill_color='color',
                  fill_alpha='fill_alpha',
                  line_color='line_color')
     yield GlyphRenderer(glyph=glyph)
Beispiel #13
0
 def build_renderers(self):
     # parse all series. We exclude the first attr as it's the x values
     # added for the index
     glyph = Patches(xs='x_values',
                     ys='y_values',
                     fill_alpha=self.fill_alpha,
                     fill_color='fill_color',
                     line_color='line_color')
     renderer = GlyphRenderer(data_source=self.source, glyph=glyph)
     yield renderer
Beispiel #14
0
 def build_renderers(self):
     glyph_class = self.glyphs[self.glyph_name]
     glyph = glyph_class(x='x',
                         y='y',
                         height=self.height,
                         width=self.width,
                         fill_color=self.fill_color,
                         line_color=self.line_color,
                         dilate=True)
     yield GlyphRenderer(glyph=glyph)
Beispiel #15
0
    def __init__(self,
                 body_width=0.5,
                 body_height=0.25,
                 num_bodies=2,
                 body_distance=1.0):
        self.body_width = body_width
        self.body_height = body_height
        self.num_bodies = num_bodies
        self.rod_colors = viridis(51)
        self.body_distance = body_distance

        self.bodies = []
        self.rods = []

        for _ in range(num_bodies):
            self.bodies.append(
                GlyphRenderer(data_source=ColumnDataSource(dict(x=[0], y=[0])),
                              glyph=Rect(x='x',
                                         y='y',
                                         width=self.body_height,
                                         height=self.body_width)))

        for _ in range(num_bodies - 1):
            self.rods.append(
                GlyphRenderer(data_source=ColumnDataSource(
                    dict(x=[0, 0], y=[0, 0])),
                              glyph=Line(x='x',
                                         y='y',
                                         line_width=2,
                                         line_color=self.rod_colors[0])))

        self.ground = GlyphRenderer(data_source=ColumnDataSource(
            dict(x=[-100, 100],
                 y=[-self.body_height / 2, -self.body_height / 2])),
                                    glyph=Line(x='x',
                                               y='y',
                                               line_width=1,
                                               line_alpha=0.5))
    def yield_renderers(self):

        aw = AnnularWedge(x=0,
                          y=0,
                          inner_radius='inners',
                          outer_radius='outers',
                          start_angle='start',
                          end_angle='end',
                          fill_color='color',
                          fill_alpha=0.8,
                          line_color=self.line_color)

        yield GlyphRenderer(data_source=self.chart_data, glyph=aw)

        txt = Text(x="x",
                   y="y",
                   text="text",
                   angle="text_angle",
                   text_align="center",
                   text_baseline="middle",
                   text_font_size=self.text_font_size)

        yield GlyphRenderer(data_source=self.text_data, glyph=txt)
Beispiel #17
0
    def bokeh(self,
              glyphType="line",
              glyphSize=1,
              fillColor="red",
              lineColor="black",
              lineAlpha=1,
              fillAlpha=0.1,
              lineDash='solid'):

        #glyphs
        from bokeh.models.glyphs import Rect, Segment, Line, Patches, Arc
        from bokeh.models.renderers import GlyphRenderer
        from bokeh.models.markers import (Marker, Asterisk, Circle,
                                          CircleCross, CircleX, Cross, Diamond,
                                          DiamondCross, InvertedTriangle,
                                          Square, SquareCross, SquareX,
                                          Triangle, X)

        #data
        from bokeh.models import ColumnDataSource

        #Parameters of the histogram
        l = self.low
        h = self.high
        num = self.num
        bin_width = (h - l) / num
        x = list()
        center = l
        for _ in range(num):
            x.append(center + bin_width / 2)
            center += bin_width
        y = self.numericalValues
        ci = [2. * v for v in self.confidenceIntervalValues()]

        source = ColumnDataSource(data=dict(x=x, y=y, ci=ci))

        glyph = None
        if glyphType == "square":
            glyph = Square(x='x',
                           y='y',
                           line_color=lineColor,
                           fill_color=fillColor,
                           line_alpha=lineAlpha,
                           size=glyphSize,
                           line_dash=lineDash)
        elif glyphType == "diamond":
            glyph = Diamond(x='x',
                            y='y',
                            line_color=lineColor,
                            fill_color=fillColor,
                            line_alpha=lineAlpha,
                            size=glyphSize,
                            line_dash=lineDash)
        elif glyphType == "cross":
            glyph = Cross(x='x',
                          y='y',
                          line_color=lineColor,
                          fill_color=fillColor,
                          line_alpha=lineAlpha,
                          size=glyphSize,
                          line_dash=lineDash)
        elif glyphType == "triangle":
            glyph = Triangle(x='x',
                             y='y',
                             line_color=lineColor,
                             fill_color=fillColor,
                             line_alpha=lineAlpha,
                             size=glyphSize,
                             line_dash=lineDash)
        elif glyphType == "circle":
            glyph = Circle(x='x',
                           y='y',
                           line_color=lineColor,
                           fill_color=fillColor,
                           line_alpha=lineAlpha,
                           size=glyphSize,
                           line_dash=lineDash)
        elif glyphType == "rect":
            glyph = Rect(x='x',
                         y='y',
                         width=bin_width,
                         height=0.1,
                         fill_alpha=fillAlpha,
                         line_color=lineColor,
                         fill_color=fillColor)
        elif glyphType == "errors":
            glyph = Rect(x='x',
                         y='y',
                         width=bin_width,
                         height='ci',
                         fill_alpha=fillAlpha,
                         line_color=lineColor,
                         fill_color=fillColor)
        elif glyphType == "histogram":
            h = y
            y = [yy / 2 for yy in y]
            source = ColumnDataSource(dict(x=x, y=y, h=h))
            glyph = Rect(x='x',
                         y='y',
                         width=bin_width,
                         height='h',
                         fill_alpha=fillAlpha,
                         line_color=lineColor,
                         fill_color=fillColor)
        else:
            glyph = Line(x='x',
                         y='y',
                         line_color=lineColor,
                         line_alpha=lineAlpha,
                         line_width=glyphSize,
                         line_dash=lineDash)

        return GlyphRenderer(glyph=glyph, data_source=source)
Beispiel #18
0
 def build_renderers(self):
     yield GlyphRenderer()
Beispiel #19
0
    def plotbokeh(self, glyphType="line", glyphSize=1, fillColor="red",
                  lineColor="black", lineAlpha=1, fillAlpha=0.1, lineDash='solid'):

        # glyphs
        from bokeh.models.glyphs import Rect, Line
        from bokeh.models.renderers import GlyphRenderer
        from bokeh.models.markers import (Circle, Cross,
                                          Diamond, Square,
                                          Triangle)

        # data
        from bokeh.models import ColumnDataSource

        # Parameters of the histogram
        lo = self.low
        hi = self.high
        num = self.numFilled
        bin_width = (hi-lo)/num
        x = list()
        center = lo
        for _ in range(num):
            x.append(center+bin_width/2)
            center += bin_width
        y = [v.entries for _, v in sorted(self.bins.items())]

        source = ColumnDataSource(data=dict(x=x, y=y))

        glyph = None
        if glyphType == "square":
            glyph = Square(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "diamond":
            glyph = Diamond(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "cross":
            glyph = Cross(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "triangle":
            glyph = Triangle(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "circle":
            glyph = Circle(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "rect":
            glyph = Rect(
                x='x',
                y='y',
                width=bin_width,
                height=0.1,
                fill_alpha=fillAlpha,
                line_color=lineColor,
                fill_color=fillColor)
        elif glyphType == "errors":
            ci = [2.*v for v in self.confidenceIntervalValues()]
            source = ColumnDataSource(data=dict(x=x, y=y, ci=ci))
            glyph = Rect(
                x='x',
                y='y',
                width=bin_width,
                height='ci',
                fill_alpha=fillAlpha,
                line_color=lineColor,
                fill_color=fillColor)
        elif glyphType == "histogram":
            h = y
            y = [yy/2 for yy in y]
            source = ColumnDataSource(dict(x=x, y=y, h=h))
            glyph = Rect(
                x='x',
                y='y',
                width=bin_width,
                height='h',
                fill_alpha=fillAlpha,
                line_color=lineColor,
                fill_color=fillColor)
        else:
            glyph = Line(
                x='x',
                y='y',
                line_color=lineColor,
                line_alpha=lineAlpha,
                line_width=glyphSize,
                line_dash=lineDash)

        return GlyphRenderer(glyph=glyph, data_source=source)
Beispiel #20
0
    def plotbokeh(self, glyphType="line", glyphSize=1, fillColor="red",
                  lineColor="black", lineAlpha=1, fillAlpha=0.1, lineDash='solid'):

        # glyphs
        from bokeh.models.glyphs import Rect, Line
        from bokeh.models.renderers import GlyphRenderer
        from bokeh.models.markers import (Circle, Cross,
                                          Diamond, Square,
                                          Triangle)

        # data
        from bokeh.models import ColumnDataSource

        # Parameters of the histogram
        lo = self.low
        hi = self.high
        num = self.num
        bin_width = (hi-lo)/num
        x = list()
        y = list()
        center = lo
        for v in self.values:
            if not math.isnan(v.mean):
                y.append(v.mean)
                x.append(center+bin_width/2)
                center += bin_width

        source = ColumnDataSource(data=dict(x=x, y=y))

        glyph = None
        if glyphType == "square":
            glyph = Square(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "diamond":
            glyph = Diamond(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "cross":
            glyph = Cross(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "triangle":
            glyph = Triangle(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "circle":
            glyph = Circle(
                x='x',
                y='y',
                line_color=lineColor,
                fill_color=fillColor,
                line_alpha=lineAlpha,
                size=glyphSize,
                line_dash=lineDash)
        elif glyphType == "histogram":
            w = [bin_width for _ in x]
            h = y
            y = [yy/2 for yy in y]
            source = ColumnDataSource(dict(x=x, y=y, w=w, h=h))
            glyph = Rect(
                x='x',
                y='y',
                width='w',
                height='h',
                fill_alpha=fillAlpha,
                line_color=lineColor,
                fill_color=fillColor)
        else:
            glyph = Line(
                x='x',
                y='y',
                line_color=lineColor,
                line_alpha=lineAlpha,
                line_width=glyphSize,
                line_dash=lineDash)

        return GlyphRenderer(glyph=glyph, data_source=source)
Beispiel #21
0
    bis.show(p)
    assert p in curstate().document.roots


@patch('bokeh.io.showing._show_with_state')
def test_show_doesnt_duplicate_if_already_there(m):
    curstate().reset()
    assert curstate().document.roots == []
    p = Plot()
    bis.show(p)
    assert curstate().document.roots == [p]
    bis.show(p)
    assert curstate().document.roots == [p]


@pytest.mark.parametrize('obj', [1, 2.3, None, "str", GlyphRenderer()])
def test_show_with_bad_object(obj):
    with pytest.raises(ValueError):
        bis.show(obj)


#-----------------------------------------------------------------------------
# Dev API
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Private API
#-----------------------------------------------------------------------------


@patch('bokeh.io.showing.run_notebook_hook')
Beispiel #22
0
    def bokeh(self,
              glyphType="line",
              glyphSize=1,
              fillColor="red",
              lineColor="black",
              lineAlpha=1,
              fillAlpha=0.1,
              lineDash='solid'):

        #glyphs
        from bokeh.models.glyphs import Rect, Segment, Line, Patches, Arc
        from bokeh.models.renderers import GlyphRenderer
        from bokeh.models.markers import (Marker, Asterisk, Circle,
                                          CircleCross, CircleX, Cross, Diamond,
                                          DiamondCross, InvertedTriangle,
                                          Square, SquareCross, SquareX,
                                          Triangle, X)

        #data
        from bokeh.models import ColumnDataSource

        from math import sqrt

        #Parameters of the histogram
        l = self.low
        h = self.high
        num = self.num
        bin_width = (h - l) / num
        x = list()
        y = list()
        center = l
        for v in self.values:
            if not math.isnan(v.mean):
                y.append(v.mean)
                x.append(center + bin_width / 2)
                center += bin_width

        source = ColumnDataSource(data=dict(x=x, y=y))

        glyph = None
        if glyphType == "square":
            glyph = Square(x='x',
                           y='y',
                           line_color=lineColor,
                           fill_color=fillColor,
                           line_alpha=lineAlpha,
                           size=glyphSize,
                           line_dash=lineDash)
        elif glyphType == "diamond":
            glyph = Diamond(x='x',
                            y='y',
                            line_color=lineColor,
                            fill_color=fillColor,
                            line_alpha=lineAlpha,
                            size=glyphSize,
                            line_dash=lineDash)
        elif glyphType == "cross":
            glyph = Cross(x='x',
                          y='y',
                          line_color=lineColor,
                          fill_color=fillColor,
                          line_alpha=lineAlpha,
                          size=glyphSize,
                          line_dash=lineDash)
        elif glyphType == "triangle":
            glyph = Triangle(x='x',
                             y='y',
                             line_color=lineColor,
                             fill_color=fillColor,
                             line_alpha=lineAlpha,
                             size=glyphSize,
                             line_dash=lineDash)
        elif glyphType == "circle":
            glyph = Circle(x='x',
                           y='y',
                           line_color=lineColor,
                           fill_color=fillColor,
                           line_alpha=lineAlpha,
                           size=glyphSize,
                           line_dash=lineDash)
        elif glyphType == "errors":
            w = [bin_width for _ in x]
            h = [
                sqrt(v.variance / v.entries) if v.entries > 0 else 0.0
                for v in self.values
            ]
            source = ColumnDataSource(dict(x=x, y=y, w=w, h=h))
            glyph = Rect(x='x',
                         y='y',
                         width='w',
                         height='h',
                         fill_alpha=fillAlpha,
                         line_color=lineColor,
                         fill_color=fillColor)
        elif glyphType == "histogram":
            w = [bin_width for _ in x]
            h = y
            y = [yy / 2 for yy in y]
            source = ColumnDataSource(dict(x=x, y=y, w=w, h=h))
            glyph = Rect(x='x',
                         y='y',
                         width='w',
                         height='h',
                         fill_alpha=fillAlpha,
                         line_color=lineColor,
                         fill_color=fillColor)
        else:
            glyph = Line(x='x',
                         y='y',
                         line_color=lineColor,
                         line_alpha=lineAlpha,
                         line_width=glyphSize,
                         line_dash=lineDash)

        return GlyphRenderer(glyph=glyph, data_source=source)
Beispiel #23
0
def get_graph_elems(graph):
    '''
    Convert the Networkx graph object into a graph that can be rendered by Bokeh. Creates node and edge
    renderers for the graph, labels for the nodes and interactivity for clicking on nodes (displaying just
    the node and all its linked edges). 
    '''

    # get all nodes
    node_ids = list(graph.nodes())

    # get all edges including for each edge:
    # -start and end nodes (the players in the player pair)-- kind of arbitrary since the graph is
    # undirected
    # -weight (the estimated net points for each player pair)
    # -color (red if negative, black if positive)
    start_ids = [a for a, b in graph.edges()]
    end_ids = [b for a, b in graph.edges()]
    weights = [.025 * graph[a][b]['weight'] for a, b in graph.edges()]
    colors = [graph[a][b]['color'] for a, b in graph.edges()]

    # define data sources for nodes and edges
    graph_layout, label_layout = get_graph_layout(graph)
    x_graph, y_graph = [v[0] for v in graph_layout.values()
                        ], [v[1] for v in graph_layout.values()]
    x_label, y_label = [v[0] for v in label_layout.values()
                        ], [v[1] for v in label_layout.values()]

    node_ds = ColumnDataSource(data=dict(index=list(graph.nodes()),
                                         x=x_graph,
                                         y=y_graph,
                                         color=[Spectral4[0]] *
                                         len(list(graph.nodes()))),
                               name="Node Renderer")
    edge_ds = ColumnDataSource(data=dict(start=start_ids,
                                         end=end_ids,
                                         weight=weights,
                                         color=colors),
                               name="Edge Renderer")

    # create bokeh graph object
    # note that both nodes and edges both have specified "glyphs" for regular and selection/nonselection (as well as
    # the selection policy (NodesAndLinkedEdges())
    # when a node is selected, its outgoing edges are highlighted
    graph_plot = GraphRenderer(
        node_renderer=GlyphRenderer(glyph=Circle(size=15, fill_color="color"),
                                    selection_glyph=Circle(size=15,
                                                           fill_color="color"),
                                    data_source=node_ds),
        edge_renderer=GlyphRenderer(
            glyph=MultiLine(line_alpha=0.3,
                            line_width='weight',
                            line_color='color'),
            selection_glyph=MultiLine(line_alpha=1,
                                      line_width='weight',
                                      line_color='color'),
            nonselection_glyph=MultiLine(line_alpha=0,
                                         line_width='weight',
                                         line_color='color'),
            data_source=edge_ds),
        layout_provider=StaticLayoutProvider(graph_layout=graph_layout),
        selection_policy=NodesAndLinkedEdges())

    # create labels for each node as well as their positions when plotted
    label_ds = ColumnDataSource(
        data=dict(index=list(graph.nodes()), x=x_label, y=y_label))
    labels = LabelSet(x='x',
                      y='y',
                      text='index',
                      source=label_ds,
                      background_fill_color='lightgrey')

    return graph_plot, labels