HTML version of this notebook with outputs: https://statistikstadtzuerich.github.io/ssz-palette/example.html
SSZ Palette provides commonly used colormaps of Statistik Stadt Zürich (SSZ) for matplotlib.
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
import sszpalette
# register the ssz color palette
colorsmaps = sszpalette.register()
colorsmaps
# set the default colormap and the color cycle
plt.set_cmap('contrasting12') # or any other colormap
plt.rcParams['axes.prop_cycle'] = plt.cycler(color=plt.get_cmap().colors)
# This uses the default colormap and default prop cycle defined above
x = np.linspace(0, 20, 100)
fig, ax = plt.subplots()
for i in range(10):
ax.plot(x, i * np.cos(x))
plt.show()
# create mock data
data = np.random.random([100, 100]) * 10
plt.figure(figsize=(7, 6))
plt.pcolormesh(data, cmap='sequential9petrol')
plt.colorbar(orientation='horizontal')
# 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()
# Indices to step through colormap.
x = np.linspace(0.0, 1.0, 100)
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))
def plot_color_gradients(cmap_list):
nrows = len(cmap_list)
figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22
fig, axs = plt.subplots(nrows=len(cmap_list), ncols=1, figsize=(6.4, figh))
fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99,
wspace=0.05)
fig.suptitle('SSZ palette colormaps', fontsize=18, y=1.0, x=0.6)
for ax, name in zip(axs, cmap_list):
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
pos = list(ax.get_position().bounds)
x_text = pos[0] - 0.01
y_text = pos[1] + pos[3]/2.
fig.text(x_text, y_text, name, va='center', ha='right', fontsize=14)
# Turn off *all* ticks & spines, not just the ones with colormaps.
for ax in axs.flat:
ax.set_axis_off()
plt.show()
plot_color_gradients(colorsmaps)