Extended colors for python
Project description
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
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.8.tar.gz
(16.2 kB
view details)
File details
Details for the file excolor-0.0.8.tar.gz
.
File metadata
- Download URL: excolor-0.0.8.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 140a98c6256764e6cad9ada68a37686260be1f08bde6cd1a06977434729f0eef |
|
MD5 | 345e23cde8c49f8377caf55db25ae190 |
|
BLAKE2b-256 | 21731654c0aca299a86886b8b8279e30b31be8abcfad476c43e924ee98a33fe0 |