コード例 #1
0
    def render(**figure_kwargs):

        figure = Figure(**figure_kwargs)
        figure.add_layout(Legend())
        figure.legend.location = "top_left"
        figure.legend.click_policy = "hide"

        figure.line(legend_label=yfast,
                    source=onesource,
                    x='datetime',
                    y=yfast,
                    color='red')
        figure.line(legend_label=yslow,
                    source=onesource,
                    x='datetime',
                    y=yslow,
                    color='blue')
        figure.segment(legend_label=y1hist,
                       source=onesource,
                       x0='datetime',
                       x1='datetime',
                       y0=0,
                       y1=y1hist,
                       line_width=6,
                       color='black',
                       alpha=0.5)

        return figure
コード例 #2
0
    def render(**figure_kwargs):

        figure = Figure(**figure_kwargs)

        figure.segment(source=onesource,
                       legend_label="OHLC H/L",
                       x0='datetime',
                       x1='datetime',
                       y0='low',
                       y1='high',
                       line_width=1,
                       color='black')

        updown = [
            o < c
            for o, c in zip(onesource.data['open'], onesource.data['close'])
        ]

        figure.vbar(
            legend_label="OHLC Up",
            source=onesource,
            view=CDSView(source=onesource, filters=[BooleanFilter(updown)]),
            width=(onesource.data['datetime'][1] -
                   onesource.data['datetime'][0]) / 2,
            x='datetime',
            bottom='open',
            top='close',
            fill_color="#D5E1DD",
            line_color="black",
        )

        figure.vbar(
            legend_label="OHLC Down",
            source=onesource,
            view=CDSView(source=onesource,
                         filters=[BooleanFilter([not b for b in updown])]),
            width=(onesource.data['datetime'][1] -
                   onesource.data['datetime'][0]) / 2,
            x='datetime',
            top='open',
            bottom='close',
            fill_color="#F2583E",
            line_color="black",
        )

        # point of calling super.__call__() ?? Legend ??
        figure.legend.location = "top_left"
        figure.legend.click_policy = "hide"

        return figure
コード例 #3
0
    def __plot_stem_and_bulb(figure, series, color, name):

        figure.circle(x="index",
                      y=name,
                      source=ColumnDataSource(series.to_frame()),
                      alpha=0.5,
                      size=10,
                      color=color)

        figure.segment(x0='index',
                       x1='index',
                       y0=0,
                       y1=name,
                       source=ColumnDataSource(series.to_frame()),
                       line_width=1,
                       color=color)
        return figure
コード例 #4
0
ファイル: diagonal.py プロジェクト: gribskov/biocomputing
    def bdot(self,
             dataname,
             figurename,
             width=1,
             color=1,
             mode='dot',
             set_colormap=True):
        """-----------------------------------------------------------------------------------------
        Bokeh plot of dots in the main panel, and colorbar in the legend panel

        :param dataname: string, name of a dataframe in self.frame
        :param figurename: string, a figure defined in setupBokeh and stored in self.figure
        :param width: boolean, scale size of markers by the score
        :param color: boolean, scale the color of the markers by the score
        :param mode: string, if dot use the circle renderer, otherwise segment renderer
        :param set_colormap: boolean, set the colormap based on score range, turn off for second
        plot to use the same scale
        :return: True
        -----------------------------------------------------------------------------------------"""
        data = self.frame[dataname]
        figure = self.figure[figurename]
        legend = self.figure['legend']
        window = self.window
        threshold = self.threshold
        alpha = self.alpha

        scoremin, scoremax = self.valueMinMax(data['score'])

        if width == 1:
            self.scaleColumn('dots', 'score', 'size',
                             (threshold - 1, scoremax),
                             (self.mindotsize, self.maxdotsize))
        else:
            data['size'] = [self.mindotsize for _ in range(len(data['score']))]

        if color == 1:
            pass
        else:
            data['score'] = [scoremax for _ in range(len(data['score']))]

        if set_colormap:
            if color == 1:
                cmap = LinearColorMapper(self.palette,
                                         low=max(threshold - 1.0,
                                                 scoremin - 1),
                                         high=scoremax)
            else:
                cmap = LinearColorMapper(self.palette,
                                         low=threshold - 0.1,
                                         high=threshold)
            self.cmap = cmap
        else:
            cmap = self.cmap

        source = ColumnDataSource(data)
        if mode == 'dot':
            figure.circle(source=source,
                          x='x',
                          y='y',
                          size='size',
                          line_color=transform('score', cmap),
                          line_alpha=alpha,
                          fill_color=transform('score', cmap),
                          fill_alpha=alpha)

        else:
            # line mode
            figure.segment(source=source,
                           x0='x',
                           x1='x1',
                           y0='y',
                           y1='y1',
                           line_width='size',
                           line_color=transform('score', cmap),
                           alpha=alpha)

        # color bar is in a separate window, self.legend, so it doesn't disturb the
        # aspect ratio
        if color:
            color_bar = ColorBar(color_mapper=cmap,
                                 label_standoff=3,
                                 bar_line_color='black',
                                 scale_alpha=alpha,
                                 width=20,
                                 margin=0,
                                 location=(0, 0),
                                 major_tick_in=20,
                                 major_tick_out=5,
                                 major_tick_line_color='black')

            legend.add_layout(color_bar, 'left')

        return True