Create colormaps from images
Project description
Create colormaps from images in three lines of code!
First, ImageConverter class converts images to arrays of RGB values.
Then, generate_cmap creates a matplotlib ListedColormap.
from img2cmap import ImageConverter
converter = ImageConverter("tests/images/south_beach_sunset.jpg")
cmap = converter.generate_cmap(n_colors=5, palette_name="south_beach_sunset", random_state=42)
Plot an image and a colorbar side by side.
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
fig, ax = plt.subplots(figsize=(7, 5))
ax.axis("off")
img = plt.imread("tests/images/south_beach_sunset.jpg")
im = ax.imshow(img, cmap=cmap)
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="10%", pad=0.05)
cb = fig.colorbar(im, cax=cax, orientation="vertical", label=cmap.name)
cb.set_ticks([])
Now, use the colormap in your plots!
import matplotlib.pyplot as plt
colors = colormap.colors
with plt.style.context("dark_background"):
for i, color in enumerate(colors):
plt.plot(range(10), [_+i+1 for _ in range(10)], color=color, linewidth=4)
Installation
pip install img2cmap
You can also install the in-development version with:
pip install https://github.com/arvkevi/img2cmap/archive/main.zip
Documentation
Status
Development
To run all the tests run:
tox
Note, to combine the coverage data from all the tox environments run:
Windows |
set PYTEST_ADDOPTS=--cov-append tox |
---|---|
Other |
PYTEST_ADDOPTS=--cov-append tox |
Changelog
0.0.0 (2022-04-30)
First release on PyPI.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
img2cmap-0.1.0.tar.gz
(289.6 kB
view hashes)