mplcolors
A command-line information tool written in Python 3.x
Tired of searching "matplotlib colors" every week/day/hour?
mplcolors
is a command-line information tool written in Python 3.x which can display matplotlib
colors, colorbars, and has a few other useful functions.
This uses matplotlib.colors to get color names and RGB values and prints with ANSI escape sequences.
Finally, given a matplotlib
color or hex value, mplcolors
can return the RGB color complement.
It can also print all of the built-in colorbars.
Compatibility
This requires a terminal with true color support. Notably, Mac's Terminal.app does not have this and so the colors cannot be properly displayed. I'm not sure that that is a workaround for this. On Mac I suggest switching to a different terminal emulator with more modern support such as kitty, alacritty, or iTerm.
Requirements
You just need a Python distribution (3.x) with matplotlib and a true color compatible terminal emulator.
Installation
Direct Installation
- Clone this repository
git clone https://github.com/AstroBarker/mplcolors.git
. - Run
make install
inside the script directory.
- MacOS
make PREFIX=/usr/local install
OS Packages
mplcolors
is hosted on the Arch User Repository.
On an Arch-based system, you can do, e.g.,
yay -S mplcolors
Alternatively, you may create an alias in your shell's rc file (e.g., ~/.bashrc
) such as
alias mplcolors='python /path/to/dir/mplcolors.py'
although this will not install the man
file.
Usage
After installation, you may run
mplcolors
to print the default matplotlib
colors.
You may display all of the available xkcd colors by passing the option -a
or flag --all
.
To search for the RGB complement to a given color, use the -c
or --complement
flags followed by either a matplotlib
color or hex.
If using a hex value, the "#" can be given or withheld.
mplcolors -c "12ab84"
To search for colors containing a given string (e.g., "red"), then you can run:
mplcolors -s "red"
To display all of the built-in colormaps, use the -b
flag ("b" for "bars") or the --colorbars
option
mplcolors -b