Skip to main content

Extended colors for python

Project description

Python Versions PyPI License Documentation Status

excolors

Extexnded color utilities for python

Installation

pip install excolor

Extra colormaps

import excolor

cmap = plt.get_cmap("gruvbox")
cmap

Colorize black-and-white image

  • Hue and saturation cannot colorize black-and-white image. They only change pixels where levels of red, gree, blue are not the same.

  • Colorize() function takes a greyscale or b&w image and adds colors to dark and light areas.

fname = "pacman.png"

img = excolor.load_image(fname)

plt.figure(figsize=(2,2), facecolor="#00000000")
plt.imshow(img)
plt.axis("off")
plt.show()

img = excolor.colorize(fname, "yellow", "green")

plt.figure(figsize=(2,2), facecolor="#00000000")
plt.imshow(img)
plt.axis("off")
plt.show()

Color cycler

Set ax color cycler based on cmap or list of colors

from sklearn.metrics import confusion_matrix

# Generate data for heatmap and scatter plot
np.random.seed(10)
y_true = (np.arange(50) > 25).astype(float)
x0 = np.random.normal(0,1,50) + y_true
x1 = np.random.normal(0,1,50) + y_true

# Predict y_true based on x0
y_pred = x0 > 0
c = confusion_matrix(y_true, y_pred)

# Plot heatmap of confusion matrix using "viridis" colormap
plt.figure(figsize=(4,2), facecolor="white")
plt.subplot(121)
plt.title("Heatmap")
sns.heatmap(c, annot=True, cmap="viridis", vmin=0)
plt.subplot(122)
plt.title("Scatterplot")

# Set "viridis" colors for color cycler to make scatter plot
excolor.set_color_cycler("viridis", n=2)
for i in range(2):
    mask = y_true == i
    plt.scatter(x0[mask], x1[mask])
plt.tight_layout()
plt.show()


Log-scaling colormaps

Color perlin noise using log-scaled colormap to visualize water caustics

from pythonperlin import perlin

dens = 32
shape = (8,8)
x = perlin(shape, dens=dens)

# Log-scaled colormap
cmap = excolor.logscale_cmap("GnBu_r")

plt.figure(figsize=(6,6), facecolor="#00000000")
plt.imshow( np.abs(x), cmap=cmap)
plt.axis("off")
plt.show()

Documentation

https://excolor.readthedocs.io

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

excolor-0.0.7.tar.gz (16.2 kB view details)

Uploaded Source

File details

Details for the file excolor-0.0.7.tar.gz.

File metadata

  • Download URL: excolor-0.0.7.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.19

File hashes

Hashes for excolor-0.0.7.tar.gz
Algorithm Hash digest
SHA256 c50b49fe5d0ed298acb6d0225a2c33587a8cd39358deec9f966d776c9c410685
MD5 81b8ada1913ed9077ec57550448a95af
BLAKE2b-256 099da92825ecb7e01635b74c0227109b97afbff01e17a02e7ad87d0e349e5ad6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page