How to use the branca.utilities.color_brewer function in branca

To help you get started, we’ve selected a few branca examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-visualization / branca / tests / test_utilities.py View on Github external
def test_color_brewer_reverse():
    scheme = ut.color_brewer('YlGnBu')
    scheme_r = ut.color_brewer('YlGnBu_r')
    assert scheme[::-1] == scheme_r
github python-visualization / branca / tests / test_utilities.py View on Github external
def test_color_brewer_base():
    scheme = ut.color_brewer('YlGnBu', 9)
    assert scheme == [
        '#ffffd9', '#edf8b1', '#c7e9b4',
        '#7fcdbb', '#41b6c4', '#1d91c0',
        '#225ea8', '#253494', '#081d58'
    ]
github python-visualization / branca / tests / test_utilities.py View on Github external
def test_color_brewer_reverse():
    scheme = ut.color_brewer('YlGnBu')
    scheme_r = ut.color_brewer('YlGnBu_r')
    assert scheme[::-1] == scheme_r
github python-visualization / folium / folium / features.py View on Github external
if color_data is not None and key_on is not None:
            real_values = np.array(list(color_data.values()))
            real_values = real_values[~np.isnan(real_values)]
            _, bin_edges = np.histogram(real_values, bins=bins)

            bins_min, bins_max = min(bin_edges), max(bin_edges)
            if np.any((real_values < bins_min) | (real_values > bins_max)):
                raise ValueError(
                    'All values are expected to fall into one of the provided '
                    'bins (or to be Nan). Please check the `bins` parameter '
                    'and/or your data.')

            # We add the colorscale
            nb_bins = len(bin_edges) - 1
            color_range = color_brewer(fill_color, n=nb_bins)
            self.color_scale = StepColormap(
                color_range,
                index=bin_edges,
                vmin=bins_min,
                vmax=bins_max,
                caption=legend_name)

            # then we 'correct' the last edge for numpy digitize
            # (we add a very small amount to fake an inclusive right interval)
            increasing = bin_edges[0] <= bin_edges[-1]
            bin_edges[-1] = np.nextafter(
                bin_edges[-1],
                (1 if increasing else -1) * np.inf)

            key_on = key_on[8:] if key_on.startswith('feature.') else key_on
github python-visualization / folium / folium / features.py View on Github external
def __init__(self, geo_data, data=None, columns=None, key_on=None,  # noqa
                 bins=6, fill_color='blue', nan_fill_color='black',
                 fill_opacity=0.6, nan_fill_opacity=None, line_color='black',
                 line_weight=1, line_opacity=1, name=None, legend_name='',
                 overlay=True, control=True, show=True,
                 topojson=None, smooth_factor=None, highlight=None,
                 **kwargs):
        super(Choropleth, self).__init__(name=name, overlay=overlay,
                                         control=control, show=show)
        self._name = 'Choropleth'

        if data is not None and not color_brewer(fill_color):
            raise ValueError('Please pass a valid color brewer code to '
                             'fill_local. See docstring for valid codes.')

        if nan_fill_opacity is None:
            nan_fill_opacity = fill_opacity

        if 'threshold_scale' in kwargs:
            if kwargs['threshold_scale'] is not None:
                bins = kwargs['threshold_scale']
            warnings.warn(
                'choropleth `threshold_scale` parameter is now depreciated '
                'in favor of the `bins` parameter.', DeprecationWarning)

        # Create color_data dict
        if hasattr(data, 'set_index'):
            # This is a pd.DataFrame