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%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2021-05-31 10:28:17 +02:00
docs Add line chart example 2021-05-31 10:19:34 +02:00
sszpalette Remove comment 2021-05-18 09:45:27 +02:00
.gitignore Add initial version 2021-04-12 14:45:28 +02:00
LICENSE Initial commit 2021-04-12 13:56:07 +02:00
pyproject.toml Add initial version 2021-04-12 14:45:28 +02:00
README.md Add note about color cycle and default colormap 2021-05-31 10:02:45 +02:00
requirements.txt Add initial version 2021-04-12 14:45:28 +02:00
SSZ Palette in Matplotlib.ipynb Fix spaces when calling method 2021-05-31 10:28:17 +02:00

ssz-palette

Color palette for matplotlib

Overview

Here is a list of all available colormaps in this module:

Overview of available colormaps

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:

Scatter with harmonic6 colormap

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.