Пример #1
0
def create_graph(graph: figure, data: ColumnDataSource,
                 graph_params: Dict) -> figure:
    '''
    Creates a scatter plot by given parameters
    '''

    coloring = ''
    use_bucket_colorization = graph_params['use_bucket_colorization']
    if use_bucket_colorization:
        number_of_colors = graph_params['number_of_colors']
        factors_list = graph_params['factors_list']
    y_value = graph_params['y_value']
    graph_point_size = graph_params['graph_point_size']
    palette = graph_params['palette']

    if use_bucket_colorization and number_of_colors <= 11:
        factors_list = get_factors(number_of_colors)
        color_mapper = CategoricalColorMapper(
            factors=factors_list, palette=palette[number_of_colors])
        logger.info(f'{number_of_colors} color buckets created')
        graph.scatter(source=data,
                      x='number',
                      y=y_value,
                      color={
                          'field': 'color_bucket',
                          'transform': color_mapper
                      },
                      size=graph_point_size)
        coloring = palette_name.lower()
    else:
        base_color = '#3030ff'
        logger.info('Base coloring')
        graph.scatter(source=data,
                      x='number',
                      y=y_value,
                      color=base_color,
                      size=graph_point_size)
        coloring = 'monocolor'

    return graph, coloring
Пример #2
0
def bokeh_scatter(x,
                  y,
                  name: pd.Series = None,
                  x_err=None,
                  pay_norm: int = 1,
                  x_label: str = '',
                  y_label: str = '',
                  x_range: list = tuple([0, 500]),
                  title: str = '',
                  size: Union[int, float] = 4,
                  bc: str = "#f0f0f0",
                  bfc: str = "#fafafa",
                  fc="#f8b739",
                  ec="#f8b739",
                  alpha=0.5,
                  label: Optional[str] = None,
                  s: figure = None):

    if s is None:
        s = bokeh_scatter_init(pay_norm,
                               x_label,
                               y_label,
                               title=title,
                               x_range=x_range,
                               bc=bc,
                               bfc=bfc,
                               plot_constants=True)

    if x_err is not None:
        bin_range = ColumnDataSource(
            data=dict(base=y, lower=x_err[0], upper=x_err[1]))
        w = Whisker(source=bin_range,
                    base='base',
                    lower='lower',
                    upper='upper',
                    dimension='width',
                    line_color=fc)
        w.upper_head.line_color = fc
        w.lower_head.line_color = fc
        s.add_layout(w)

    if name is not None:
        source = ColumnDataSource(data=dict(x=x, y=y, name=name))

        s.scatter('x',
                  'y',
                  marker='circle',
                  fill_color=fc,
                  source=source,
                  line_color=ec,
                  alpha=alpha,
                  size=size,
                  legend_label=label)
    else:
        s.scatter('x',
                  'y',
                  marker='circle',
                  fill_color=fc,
                  line_color=ec,
                  alpha=alpha,
                  size=size,
                  legend_label=label)

    return s