Beispiel #1
0
def create_figure(m, m_source, columns):
    print("creating figure with x = %s, y = %s, color = %s, size = %s" %
          (x.value, y.value, color.value, size.value))

    tooltips = [("id", "@id"), (x.value, "@{%s}" % x.value),
                (y.value, "@{%s}" % y.value)]
    if color.value != 'None':
        tooltips += [(color.value, "@{%s}" % color.value)]
    if size.value != 'None':
        tooltips += [(size.value, "@{%s}" % size.value)]

    x_range = range_defaults[x.value] if x.value in range_defaults else None
    y_range = range_defaults[y.value] if y.value in range_defaults else None

    p = figure(plot_height=800,
               plot_width=800,
               x_range=x_range,
               y_range=y_range,
               tooltips=tooltips,
               tools=["tap", "hover", "box_select", "reset", "save"],
               title=("%s: %s vs %s" % (data.value, y.value, x.value)))
    p.xaxis.axis_label = x.value
    p.yaxis.axis_label = y.value

    sz = 8
    print("size.value = '%s'" % size.value)
    if size.value != 'None':
        if (size.value + "_plotsize") in m:
            sz = size.value + "_plotsize"
        else:
            sz = size.value
        print(sz)

    mapper = None
    c = "#31AADE"
    if color.value != 'None':
        if color.value in colormap_overrides:
            colormap_args = colormap_overrides[color.value]
        else:
            colormap_args = dict(palette=Viridis5)

        if 'low' not in colormap_args:
            colormap_args['low'] = m[color.value].min()
        if 'high' not in colormap_args:
            colormap_args['high'] = m[color.value].max()

        print(color.value, colormap_args)

        mapper = linear_cmap(field_name=color.value, **colormap_args)
        c = mapper

    p.circle(x=x.value,
             y=y.value,
             color=c,
             size=sz,
             line_color=c,
             alpha=0.4,
             hover_color='white',
             hover_alpha=0.7,
             source=m_source)

    fs = "1.3em"
    if mapper:
        color_bar = ColorBar(color_mapper=mapper['transform'],
                             width=8,
                             location=(0, 0))
        color_bar.major_label_text_font_size = fs
        color_bar.major_label_text_align = "left"
        p.add_layout(color_bar, 'right')

    p.yaxis.axis_label_text_font_size = fs
    p.yaxis.major_label_text_font_size = fs
    p.xaxis.axis_label_text_font_size = fs
    p.xaxis.major_label_text_font_size = fs
    p.title.text_font_size = fs

    return p
Beispiel #2
0
             source=heatmap_source,
             width=1,
             height=1,
             fill_color=transform('counts', mapper),
             line_color=None)

labels = LabelSet(x="DAY_OF_WEEK",
                  y="HOUR",
                  text="counts",
                  source=heatmap_source,
                  text_font_size='1em',
                  x_offset=-10,
                  y_offset=-10)

colorbar = ColorBar(color_mapper=mapper, location=(0, 0))
colorbar.major_label_text_align = 'left'

heatmap.add_layout(labels)
heatmap.add_layout(colorbar, "right")

heatmap.axis.axis_line_color = None
heatmap.axis.major_tick_line_color = None
heatmap.axis.major_label_text_font_size = "8pt"
heatmap.axis.major_label_standoff = 0


def update_top10():
    start_date, end_date = selected_months.value_as_date
    data = get_top10_groups(start_date, end_date,
                            [districts[i]
                             for i in selected_districts.active]).sort_values(