mirror of
https://github.com/StatistikStadtZuerich/ssz-palette.git
synced 2026-08-26 00:44:27 +00:00
Color palette for matplotlib | Read-only mirror of https://github.com/StatistikStadtZuerich/ssz-palette — Stadt Zürich. Issues & pull requests at the source.
- Jupyter Notebook 62.5%
- Python 37.5%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| docs | ||
| sszpalette | ||
| .gitignore | ||
| LICENSE | ||
| pyproject.toml | ||
| README.md | ||
| requirements.txt | ||
| SSZ Palette in Matplotlib.ipynb | ||
ssz-palette
Color palette for matplotlib
Overview
Here is a list of all available colormaps in this module:
Installation
To install ssz-palette from GitHub run the following command:
pip install git+https://github.com/StatistikStadtZuerich/ssz-palette.git#egg=sszpalette
Usage
To use one of the defined colormaps with matplotlib, simply import this module, register the colormaps and start using them:
import numpy as np
import matplotlib.pyplot as plt
import sszpalette
# register the ssz color palette
colorsmaps = sszpalette.register()
register() returns the names of all added colormaps (e.g. harmonic6).
To then use this colormap, simply provide it's name to the plot:
# create mock data
x,y,c = zip(*np.random.rand(30,3)*4-2)
norm = plt.Normalize(-2,2)
# scatter plot with harmonic6 colormap
plt.scatter(x,y,c=c, cmap='harmonic6', norm=norm)
plt.colorbar()
plt.show()
Result:
To change the default colormap and set the color cycle (e.g. used for the colors of line charts), use the following snippet:
plt.set_cmap('contrasting12') # or any other colormap
plt.rcParams['axes.prop_cycle'] = plt.cycler(color=plt.get_cmap().colors)
See the Jupyter Notebook SSZ Palette in Matplotlib.ipynb (HTML version) for a complete example.

