splot.mapping.value_by_alpha_cmap(x, y, cmap='GnBu', revert_alpha=False, divergent=False)[source]

Calculates Value by Alpha rgba values


Variable determined by color


Variable determining alpha value

cmapstr or list of str

Matplotlib Colormap or list of colors used to create vba_layer

revert_alphabool, optional

If True, high y values will have a low alpha and low values will be transparent. Default =False.

divergentbool, optional

Creates a divergent alpha array with high values at the extremes and low, transparent values in the middle of the input values.

rgbandarray (n,4)

RGBA colormap, where the alpha channel represents one attribute (x) and the rgb color the other attribute (y)

cmapstr or list of str

Original Matplotlib Colormap or list of colors used to create vba_layer



>>> from libpysal import examples
>>> import geopandas as gpd
>>> import matplotlib.pyplot as plt
>>> import matplotlib
>>> import numpy as np
>>> from splot.mapping import value_by_alpha_cmap

Load Example Data

>>> link_to_data = examples.get_path('columbus.shp')
>>> gdf = gpd.read_file(link_to_data)
>>> x = gdf['HOVAL'].values
>>> y = gdf['CRIME'].values

Create rgba values

>>> rgba, _ = value_by_alpha_cmap(x, y)

Create divergent rgba and change Colormap

>>> div_rgba, _ = value_by_alpha_cmap(x, y, cmap='seismic', divergent=True)

Create rgba values with reverted alpha values

>>> rev_rgba, _  = value_by_alpha_cmap(x, y, cmap='RdBu', revert_alpha=True)

(Source code)