示例#1
0
文件: trail.py 项目: chakas/bokeh
def altitude_profile(data):
    plot = Plot(title="%s - Altitude Profile" % title, plot_width=800, plot_height=400)
    plot.x_range = DataRange1d()
    plot.y_range = DataRange1d()

    xaxis = LinearAxis(axis_label="Distance (km)")
    plot.add_layout(xaxis, 'below')

    yaxis = LinearAxis(axis_label="Altitude (m)")
    plot.add_layout(yaxis, 'left')

    xgrid = Grid(plot=plot, dimension=0, ticker=xaxis.ticker)
    ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker)
    plot.renderers.extend([xgrid, ygrid])

    plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())

    X, Y = data.dist, data.alt
    y0 = min(Y)

    patches_source = ColumnDataSource(dict(
        xs=[[X[i], X[i+1], X[i+1], X[i]] for i in range(len(X[:-1])) ],
        ys=[[y0,   y0,     Y[i+1], Y[i]] for i in range(len(Y[:-1])) ],
        color=data.colors[:-1]
    ))
    patches = Patches(xs="xs", ys="ys", fill_color="color", line_color="color")
    plot.add_glyph(patches_source, patches)

    line_source = ColumnDataSource(dict(x=data.dist, y=data.alt))
    line = Line(x='x', y='y', line_color="black", line_width=1)
    plot.add_glyph(line_source, line)

    return plot
示例#2
0
def altitude_profile(data):
    plot = Plot(title="%s - Altitude Profile" % title,
                plot_width=800,
                plot_height=400)
    plot.x_range = DataRange1d()
    plot.y_range = DataRange1d(range_padding=0)

    xaxis = LinearAxis(axis_label="Distance (km)")
    plot.add_layout(xaxis, 'below')

    yaxis = LinearAxis(axis_label="Altitude (m)")
    plot.add_layout(yaxis, 'left')

    plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))  # x grid
    plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))  # y grid

    plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())

    X, Y = data.dist, data.alt
    y0 = min(Y)

    patches_source = ColumnDataSource(
        dict(xs=[[X[i], X[i + 1], X[i + 1], X[i]] for i in range(len(X[:-1]))],
             ys=[[y0, y0, Y[i + 1], Y[i]] for i in range(len(Y[:-1]))],
             color=data.colors[:-1]))
    patches = Patches(xs="xs", ys="ys", fill_color="color", line_color="color")
    plot.add_glyph(patches_source, patches)

    line_source = ColumnDataSource(dict(x=data.dist, y=data.alt))
    line = Line(x='x', y='y', line_color="black", line_width=1)
    plot.add_glyph(line_source, line)

    return plot
    def st_plot_wind_pressure(self):
        """
        Plot wind pressure along the sign face.
        The value may change for 45 degrees and a large aspect ratio.
        """
        #Set up plot
        plot = Plot()

        #Graph of Drag Factors along sign
        x = np.linspace(0, self.sign_w, num=50)
        if self.wind.loadcase is Cases.FAT:
            y = [
                0.5 * 1.2 * self.wind.V_sit_beta.value**2 * self.C_dyn / 1000 *
                self.C_fig for ix in x
            ]
        else:
            y = [
                0.5 * 1.2 * self.wind.V_sit_beta.value**2 *
                self.C_dyn * self.K_p / 1000 * self.C_pn_func(
                    self.sign_w, self.sign_h, self.wind.Wind_mult.height, ix)
                for ix in x
            ]
        source = ColumnDataSource(dict(x=x, y=y))
        drag_factor = Line(x='x', y='y', line_color="#f46d43", line_width=3)
        plot.add_glyph(source, drag_factor)

        #Fille area under line
        fill_under = Band(base='x',
                          upper='y',
                          source=source,
                          level='underlay',
                          fill_color='#55FF88')
        plot.add_layout(fill_under)

        #Plot setup
        plot.add_layout(LinearAxis(), 'below')
        plot.add_layout(LinearAxis(), 'left')
        plot.xaxis.axis_label = "Distance along sign (m)"
        plot.yaxis.axis_label = "Wind Pressure (kPa)"
        plot.y_range = Range1d(0, max(y) * 1.3)

        return plot
示例#4
0
    def _make_graph_plot(self):
        """ Builds the graph portion of the final model.

        """
        import networkx as nx

        nodes = nx.nx_pydot.graphviz_layout(self._graph, prog="dot")
        node_x, node_y = zip(*nodes.values())
        models = [self._graph.nodes[x]["model"] for x in nodes]
        node_id = list(nodes.keys())
        node_source = ColumnDataSource(
            {"x": node_x, "y": node_y, "index": node_id, "model": models}
        )
        edge_x_coords = []
        edge_y_coords = []
        for start_node, end_node in self._graph.edges:
            edge_x_coords.extend([[nodes[start_node][0], nodes[end_node][0]]])
            edge_y_coords.extend([[nodes[start_node][1], nodes[end_node][1]]])
        edge_source = ColumnDataSource({"xs": edge_x_coords, "ys": edge_y_coords})

        p2 = Plot(outline_line_alpha=0.0)
        xinterval = max(max(node_x) - min(node_x), 200)
        yinterval = max(max(node_y) - min(node_y), 200)
        p2.x_range = Range1d(
            start=min(node_x) - 0.15 * xinterval, end=max(node_x) + 0.15 * xinterval
        )
        p2.y_range = Range1d(
            start=min(node_y) - 0.15 * yinterval, end=max(node_y) + 0.15 * yinterval
        )

        node_renderer = GlyphRenderer(
            data_source=node_source,
            glyph=Circle(x="x", y="y", size=15, fill_color="lightblue"),
            nonselection_glyph=Circle(x="x", y="y", size=15, fill_color="lightblue"),
            selection_glyph=Circle(x="x", y="y", size=15, fill_color="green"),
        )

        edge_renderer = GlyphRenderer(
            data_source=edge_source, glyph=MultiLine(xs="xs", ys="ys")
        )

        node_hover_tool = HoverTool(tooltips=[("id", "@index"), ("model", "@model")])
        node_hover_tool.renderers = [node_renderer]

        tap_tool = TapTool()
        tap_tool.renderers = [node_renderer]

        labels = LabelSet(
            x="x",
            y="y",
            text="model",
            source=node_source,
            text_font_size="8pt",
            x_offset=-20,
            y_offset=7,
        )

        help = Label(
            x=20,
            y=20,
            x_units="screen",
            y_units="screen",
            text_font_size="8pt",
            text_font_style="italic",
            text="Click on a model to see its attributes",
        )
        p2.add_layout(help)
        p2.add_layout(edge_renderer)
        p2.add_layout(node_renderer)
        p2.tools.extend(
            [node_hover_tool, tap_tool, BoxZoomTool(), ResetTool(), PanTool()]
        )
        p2.renderers.append(labels)
        self._node_source = node_source
        self._edge_source = edge_source
        return p2
def plotprotein(sequence, other_binding, dna_binding, metal_binding, active,
                variant_location):
    sequence = [i for i in sequence]
    print(len(sequence))
    sequence += [''] * (3000 - len(sequence))
    print(sequence)

    print(variant_location)
    if variant_location > 50:
        start_seq = variant_location - 50
    else:
        start_seq = 0
    if variant_location + 50 < len(sequence):
        end_seq = variant_location + 50
    else:
        end_seq = 3000
    x_values = range(0, 3000)
    #x_values = range(starting_value, value)
    source1 = ColumnDataSource(
        dict(x=x_values[start_seq:end_seq],
             y=other_binding[start_seq:end_seq],
             names=sequence[start_seq:end_seq]))
    source2 = ColumnDataSource(
        dict(x=x_values[start_seq:end_seq],
             y=dna_binding[start_seq:end_seq],
             names=sequence[start_seq:end_seq]))
    source3 = ColumnDataSource(
        dict(x=x_values[start_seq:end_seq],
             y=metal_binding[start_seq:end_seq],
             names=sequence[start_seq:end_seq]))
    source4 = ColumnDataSource(
        dict(x=x_values[start_seq:end_seq],
             y=active[start_seq:end_seq],
             names=sequence[start_seq:end_seq]))
    glyph1 = Line(x="x", y="y", line_color="red", line_width=3, line_alpha=0.6)
    glyph2 = Line(x="x",
                  y="y",
                  line_color="blue",
                  line_width=3,
                  line_alpha=0.6)
    glyph3 = Line(x="x",
                  y="y",
                  line_color="green",
                  line_width=3,
                  line_alpha=0.6)
    glyph4 = Line(x="x",
                  y="y",
                  line_color="orange",
                  line_width=3,
                  line_alpha=0.6)
    plot = Plot(title=None,
                plot_height=150,
                plot_width=1000,
                min_border=0,
                toolbar_location=None)
    plot.add_glyph(source1, glyph1)
    plot.add_glyph(source2, glyph2)
    plot.add_glyph(source3, glyph3)
    plot.add_glyph(source4, glyph4)
    plot.add_layout(
        Span(location=variant_location, dimension='height',
             line_color='black'))
    xaxis = LinearAxis()
    #YOUR_FONT_SIZE = 10
    labels = LabelSet(x='x',
                      y=1,
                      text='names',
                      level='glyph',
                      x_offset=-1,
                      y_offset=5,
                      source=source1,
                      render_mode='canvas',
                      text_font_size='5pt')
    plot.add_layout(labels)
    yaxis = LinearAxis()
    plot.add_layout(yaxis, 'left')
    plot.yaxis.bounds = (0, 1)
    plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
    plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))
    plot.y_range = Range1d(-0.1, 1.5)
    show(plot)