예제 #1
0
def draw_constant_salary_bump(s: figure, constant_list: list, pay_norm: int):
    """
    Draw lines for constant salary increase

    """

    constant_list0 = [c / pay_norm for c in constant_list]
    if CURRENCY_NORM and pay_norm == 1:
        constant_list0 = [a / 1e3 for a in constant_list]
        x_max = 2500.

    if pay_norm > 1:
        x_max = 1200.

    for c, constant in enumerate(constant_list0):
        x = np.arange(max([s.x_range.start, constant + 1]), x_max, 5)
        y = 100 * constant / (x - constant)

        if pay_norm == 1:
            text = f'${constant}k'
        else:
            text = f'${constant_list[c]/1e3}k (${constant:.2f}/hr)'

        source = ColumnDataSource(data=dict(x=x, y=y, name=[text] * len(x)))

        s.line('x', 'y', line_dash='dashed', line_color='black', source=source)

        y_label = constant_list[c] / 1e3
        x_label = constant + 100 * constant / y_label

        label = Label(x=x_label, y=y_label, text=text)
        s.add_layout(label)

    return s
예제 #2
0
    def _add_layer(cls, plot: figure,
                   layer_document: ChartLayerDocument) -> None:
        """
        Create line on a plot figure. Method creates line and adjusts it based on configuration. The line is appended to
        the provided plot.

        :param layer_document: (LayerDocument) layer document object containing ingredients and configuration.

        :param plot: (Figure) bokeh figure to create line on.

        :return: None
        """
        layer_model = layer_document.model
        layer_figure = layer_model.figure

        axis = layer_model.axis
        axis.name = axis.name or axis.data_field
        plot.yaxis.axis_label = axis.name

        plot.line(layer_document.x_axis.data_field,
                  axis.data_field,
                  color=layer_figure.colour,
                  alpha=layer_figure.opacity,
                  legend=axis.name,
                  line_width=layer_figure.size * cls._scale,
                  source=layer_document.data_source)
예제 #3
0
def figure_constructor(tool, loader, node):
    #print('Figureeeee: /n')
    fig = loader.construct_mapping(node, deep=True)
    fmt = tool.formats.get('Figure', {})

    elements = fig.pop('elements', [])
    #print('Figureeeee2: /n', elements)
    cmds = []
    ref = fig.pop("ref", "")
    callback = fig.pop("on_change", [])
    axis = tool.formats.get("Axis", {})

    for key in fig:
        val = fig[key]
        #print('Figureeeee3: /n', val,key)
        if key in ['text', 'add_tools']:
            cmds.append((key, val))
        else:
            fmt[key] = val

    figure = Figure(**fmt)

    for key, cmd in cmds:
        if key == 'add_tools':
            figure.add_tools(*cmd)
        elif key == 'text':
            figure.text(*cmd.pop('loc'), **cmd)

    for element in elements:
        key = element.pop('kind')
        if key == 'line':
            line_fmt = tool.formats.get('Line', {})
            line_fmt.update(element)
            figure.line('x', 'y', **line_fmt)
            #print('PLOT LINE: ', line_fmt, line_fmt.update(element))
        elif key == 'circle':
            circle_fmt = tool.formats.get('Circle', {})
            circle_fmt.update(element)
            figure.circle('x', 'y', **circle_fmt)
        elif key == 'image':
            print('HElooooo!!')
            image_fmt = tool.formats.get('Image', {})
            image_fmt.update(element)
            figure.image('value', 'x', 'y', 'dw', 'dh', **image_fmt)
            #print('PLOT image: ', image_fmt, image_fmt.update(element))

    for attr, val in axis.items():
        #change axis attributes, hopefully
        setattr(figure.axis, attr, val)

    if ref:
        tool.refs[ref] = figure
    if callback:
        figure.on_change(*callback)

    yield figure
예제 #4
0
def candle_plot(stocks: List, plot:figure=plot, color='blue'):
    stock, stock_day = stocks
    name = stock.data['name'].values[0]
    label = 'Mean price of ' + name
    plot.segment('shortened_date', 'high', 'shortened_date', 'low', color="black", source=stock)
    plot.vbar('inc', w, 'open_inc', 'close_inc', fill_color="#D5E1DD", line_color="black",source=stock_day)
    plot.vbar('dec', w, 'open_dec', 'close_dec', fill_color="#F2583E", line_color="black",source=stock_day)

    # stock_mean_val=whole_data[['high', 'low']].mean(axis=1)
    plot.line('shortened_date', 'mean', 
                legend_label=label, muted_alpha=0.2,
                line_color=color, alpha=0.5, source=stock)
예제 #5
0
def bokeh_pr_curve_raw(precision: Iterable[float],
                       recall: Iterable[float],
                       threshold: List[float],
                       fig: figure = None,
                       color: str = 'blue',
                       legend=None) -> LayoutDOM:
    """
    plot  precision recall curve. can add to an existing figure, or create a new one
    Args:
        precision: iterable of precision points
        recall: iterable of recall points
        threshold: iterable of threshold points which resulted in the previous $precision and $recall
        fig: if None: create a new bokeh figure, otherwise, add plot to figure one
        color: color of the plot

    Returns: precision recall bokeh plot
    """
    if fig is None:
        hover = HoverTool(tooltips=[(
            'recall',
            "$x{%0.2f}"), ('precision',
                           "$y{%0.2f}"), ('threshold', "@threshold{%0.2f}")])
        tools = "pan, wheel_zoom, box_zoom, reset"
        fig = figure(x_range=(0, 1),
                     y_range=(0, 1),
                     tools=[hover, tools],
                     title='Precision Recall Curve',
                     plot_height=350,
                     plot_width=400)

    cds = ColumnDataSource(data={
        'precision': precision,
        'recall': recall,
        'threshold': threshold
    })
    fig.line(x='recall',
             y='precision',
             line_width=2,
             source=cds,
             color=color,
             muted_alpha=0.2,
             muted_color=color)  # legend=legend
    # fig.circle(x='precision', y='recall', line_width=1, source=cds)
    fig.xaxis.axis_label = 'Recall'
    fig.yaxis.axis_label = 'Precision'
    fig.legend.click_policy = "mute"
    fig.legend.label_text_font_size = '6pt'
    return fig
예제 #6
0
    def create_line(self, fig: figure, color):
        """
        Creates the line in the specified figure based on the ColumnDataSource of this parameter.

        :param fig: bokeh figure object where this line is going to live.
        :param color: used to cycle through the colors.
        """
        return fig.line(x=f'{self.name}_time', y=self.name,
                        source=self.source, legend_label=self.name, color=color)
예제 #7
0
def setup_timeline_backend_parts(plot: figure,
                                 desc_label_source: ColumnDataSource) -> None:
    """

    :param plot:
    :param desc_label_source:
    :return:
    """
    start_date, end_date = plot.x_range.start, plot.x_range.end
    arrow_x = start_date + datetime.timedelta(days=180)

    # 補助線を引く
    plot.line([start_date, end_date], [1, 1], line_width=3, line_color='pink')
    plot.line([start_date, end_date], [0.5, 0.5],
              line_width=3,
              line_dash='dotted',
              line_color='pink')
    plot.line([start_date, end_date], [1.5, 1.5],
              line_width=3,
              line_dash='dotted',
              line_color='pink')

    # 矢印を表示する
    plot.add_layout(
        Arrow(end=VeeHead(size=15),
              line_color='black',
              x_start=arrow_x,
              y_start=1.4,
              x_end=arrow_x,
              y_end=1.1))
    plot.add_layout(
        Arrow(end=VeeHead(size=15),
              line_color='black',
              x_start=arrow_x,
              y_start=0.9,
              x_end=arrow_x,
              y_end=0.6))

    plot.text(source=desc_label_source,
              x='x',
              y='y',
              text='text',
              text_font_size='size',
              text_alpha=0.8)