Esempio n. 1
0
def use_data_source_with_color_mapper_legends_auto(d, map_width):
    #data = _make_random_data(d.keys())
    p = figure(width=map_width, height=int(round(4 / 5 * map_width)))
    color_mapper = LinearColorMapper(palette=Blues8)
    color_mapper.nan_color = 'gray'
    xs = []
    ys = []
    data = []
    for key in d.keys():
        if key == '04015':
            data.append(nan)
        else:
            data.append(random.randint(1, 8))
        xs.append(d[key]['x'])
        ys.append(d[key]['y'])
    legends = make_legends(data, Blues8)
    source = ColumnDataSource(data=dict(x=xs, y=ys, data=data, legend=legends))
    p.patches('x',
              'y',
              source=source,
              fill_color={
                  'field': 'data',
                  'transform': color_mapper
              },
              fill_alpha=0.7,
              line_color='white',
              legend='legend')
    p.legend.location = "bottom_right"
    return p
Esempio n. 2
0
def make_us_map(the_type,
                title="test map",
                plot_width=1100,
                plot_height=700,
                line_color="white",
                line_width=0.5,
                colors_dict=None,
                default_color="white",
                map_extent='continental_us',
                data=None,
                palette=Blues8,
                reverse_palette=True):
    if reverse_palette:
        palette.reverse()
    assert colors_dict == None or data == None
    choropleth = choropleth_prep.Chorpleth(the_type=the_type)
    d = _main_init_dict(_filter_points(choropleth.points_dict))
    add_data(d, 'data', data)
    add_data(d, 'legend', _make_legends(data, palette))
    xs, ys, data, legends = _sort_all_data(flatten(d, 'xs'), flatten(d, 'ys'),
                                           flatten(d, 'data'),
                                           flatten(d, 'legend'))
    color_mapper = LinearColorMapper(palette=palette)
    color_mapper.nan_color = default_color
    assert len(data) == len(xs)
    source = ColumnDataSource(data=dict(
        x=xs,
        y=ys,
        data=data,
        legend=legends,
    ))
    p = figure(title=title,
               toolbar_location="left",
               plot_width=plot_width,
               plot_height=plot_height)
    p.patches('x',
              'y',
              source=source,
              fill_color={
                  'field': 'data',
                  'transform': color_mapper
              },
              fill_alpha=0.7,
              line_color=line_color,
              line_width=line_width,
              legend='legend')

    show(p)
Esempio n. 3
0
def use_data_source_with_color_mapper_legends(d, map_width):
    p = figure(width=map_width, height=int(round(4 / 5 * map_width)))
    color_mapper = LinearColorMapper(palette=Blues8)
    color_mapper.nan_color = 'gray'
    legends = _make_legends_one(d.keys())
    source = ColumnDataSource(data=dict(x=[d[x]['x'] for x in d.keys()],
                                        y=[d[x]['y'] for x in d.keys()],
                                        data=_make_random_data(d.keys()),
                                        legend=legends))
    p.patches('x',
              'y',
              source=source,
              fill_color={
                  'field': 'data',
                  'transform': color_mapper
              },
              legend='legend')
    return p