wildlife-dynamics / ecoscope

Conservation data analytics
https://ecoscope.io
BSD 3-Clause "New" or "Revised" License
22 stars 9 forks source link

Apply color map to continuous data #95

Open walljcg opened 5 months ago

walljcg commented 5 months ago

`

define colour palette

colour_palette = [ "#1a9850", "#91cf60", "#d9ef8b", "#fee08b", "#fc8d59", "#d73027", ]

linear value interpolation

def palette_interpolation(palette=None, min=0, max=1,): if palette: bins = np.linspace(start=min, stop=max, num=len(palette)+1) bins = [f"{s:.0f}" for s in bins] val_ranges = list(zip(bins[0:], bins[1:])) val_ranges = [s[0] + '-' + s[1] for s in val_ranges] val_ranges = list(zip(val_ranges, palette)) return dict(val_ranges)

df['colour'] = list(pd.cut(df[val_column], bins=len(colour_palette), labels=colour_palette).values)

legend_dict=palette_interpolation(palette=colour_palette, min=np.nanmin(df[val_column]), max=np.nanmax(df[val_column])) `

walljcg commented 2 months ago

This issue is also related to https://github.com/wildlife-dynamics/ecoscope-workflows/issues/46

walljcg commented 2 months ago

Some possible frameworks to look into:

  1. https://plotly.com/python/colorscales/
  2. https://matplotlib.org/stable/users/explain/colors/colormaps.html
  3. https://python-visualization.github.io/branca/colormap.html
  4. https://github.com/dsc/colorbrewer-python
  5. https://jiffyclub.github.io/palettable/
  6. https://docs.bokeh.org/en/latest/docs/reference/palettes.html