Skip to content

jshn9515/pypalettes

Repository files navigation

PyPalettes

Note

PyPalettes is supported by Matplotlib Journey, an interactive online course designed to make you a master of Matplotlib. If you want to support PyPalettes and become a Matplotlib expert, consider purchasing the course!

This package is based on the R package paletteer, and all associated sub-packages (with original palettes) mentioned in the LICENSE file.

This project is forked from JosephBARBIERDARNAL/pypalettes

A large (+2500) collection of color maps for Python.

pypalettes.gif

Installation

With pip:

pip install git+https://github.com/jshn9515/pypalettes.git

Quick start

Once pypalettes is imported, all the palettes are now accessible as any other colormap in matplotlib or seaborn via the palette or cmap arguments.

Continuous palette

import matplotlib.pyplot as plt
import numpy as np

from pypalettes import get_cmap

data = np.random.randn(20, 20)
cmap = get_cmap('Sunset2', cmap_type='continuous')

plt.imshow(data, cmap=cmap)
plt.colorbar()
plt.show()

heatmap example

Categorical palette

import matplotlib.pyplot as plt
import seaborn as sns

from pypalettes import get_cmap

df = sns.load_dataset('penguins')
cmap = get_cmap('Fun')

g = sns.lmplot(
    data=df,
    x='bill_length_mm',
    y='bill_depth_mm',
    hue='species',
    palette=cmap,
)
g.set_axis_labels('Snoot length', 'Snoot depth')
plt.show()

scatterplot example

Your own palette

import matplotlib.pyplot as plt
import numpy as np

from pypalettes import add_cmap

cmap = add_cmap(
   name='my_cmap',
   cmap_type='continuous',
   colors=['#D57A6DFF', '#E8B762FF', '#9CCDDFFF', '#525052FF'],
)

x = np.linspace(0, 20, 1000)
y = np.sin(x)

plt.scatter(x, y, c=y, cmap=cmap)
plt.colorbar()
plt.show()

linechart example

Features

  • Add +2500 native palettes to matplotlib and seaborn
  • Load, customise and combine +2500 palettes
  • Create your own palettes

To find out more about using PyPalettes, use this PyPalettes guide.

Acknowledgements

PyPalettes is highly inspired (and relies on for the first one) from

A big thanks to Yan Holtz for:

Contributing

Since the core code of the library is currently quite short and simple, it does not require any major changes. However, if you have a good idea or suggestion, please open an issue.

That said, adding more palettes is an easy way to make pypalettes better! Here’s the best way to get started:

First, open your code editor and navigate to parsers/list_manual_palettes.py. You’ll find a dictionary of manually defined palettes. Add yours at the end with the following elements:

  • "name": the name of your palette
  • "palette": the colors of your palette in the following format: "['#123456', '#654321', '#162534']"
  • "source": Where does your palette come from? If you created it, your name or a link to your portfolio is valid!
  • "kind": the type of palette. View examples here
  • "paletteer-kind": just put "unknown"

Then, run:

python parsers/main.py

For a large number of palettes, please open an issue first.

About

PyPalettes: A large (+2500) collection of color maps for Python.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages