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

Calculates Value by Alpha rgba values

x : array

Variable determined by color

y : array

Variable determining alpha value

cmap : str or list of str

Matplotlib Colormap or list of colors used to create vba_layer

revert_alpha : bool, optional

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

divergent : bool, optional

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

rgba : ndarray (n,4)

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

cmap : str or list of str

Original Matplotlib Colormap or list of colors used to create vba_layer



>>> from pysal.lib import examples
>>> import geopandas as gpd
>>> import matplotlib.pyplot as plt
>>> import matplotlib
>>> import numpy as np
>>> from pysal.viz.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)