See the commends in source code for detail. My intent is color studies of so many palettes I've found that are perceptually overall similar, to get the color out in a grid with suggested "near" colors, and identify what I think are rrrlly the greatest colors of so many suggested near favorites, so I can pick from it to make a palette inspired of them but to rule them all (in my arbitrary aesthetic perception). This result is from a set of similar palettes (which I acquired from a source of many palettes and sorted into similar groups of palettes via allPalettesCompareCIECAM02.sh, which you'll find in that same repo). Those palettes I named "blue fire," which I attach here after the first image, and which you'll all find at https://github.com/earthbound19/_ebPalettes
[UPDATE: there's a lot more to light and color science than I perhaps inaccurately get at in this post. Also, try color transforms and comparisons (if the latter is possible?) in Oklab.]
I wrote a Python script that uses that library to sort any list of RGB colors (expressed in hex) so that every color has the colors most similar to it next to it. (Figuring out an algorithm that does this broke my brain–I guess in a good way.) (I also wrote a bash script that runs it against all .hexplt files (a palette file format which is one RGB hex color per line) in a directory.)
The results are better than any other color sorting I've found, possibly better than what very perceptive humans could accomplish with complicated arrays of color.
Here's an image of Prismacolor marker colors, in the order that results from sorting by this script (the order is left to right, top to bottom) :
For before/after comparison, here is an image from the same palette, but randomly sorted; the script can turn this ordering of the palette into the above much more contiguous-appearing:
(It's astonishing, but it seems like any color in that palette looks good with any other color in it, despite that the palette comprises every basic hue, and many grays and some browns. They know what they are doing at Prismacolor. I got this palette from my cousin Daniel Bartholomew, who uses those colors in his art, which you may see over here and here.)
Here is another before and after comparison of 250 randomly generated RGB colors sorted by this script. You might correctly guess from this that random color generation in the RGB space often produces garish color arrays. I wonder whether random color generation somehow done in a model more aligned with human perception (like CIECAM02) would produce more pleasing results.
See how it has impressive runs of colors very near each other, including by tint or shade, and good compromises when colors aren't near, with colors that are perceptually further from everything at the end. Also notice that darker and lighter shades of the same hue tend to go in separate lighter/darker runs–with colors that well interpolate into those runs in between!–instead of having lights and darks in the same run, where the higher difference of tint/shade would introduce a discontiguous aspect.
Tangent: in RGB space, I tested a theory that a collection of colors which add (or subtract!) to gray will generally be a pleasing combination of colors–and found this to be often true. I would like to test this theory in the CIECAM02 color space. I'd also like to test the theory that colors randomly generated in the CIECAM02 space will generally be more pleasing alone and together (regardless of whether they were conceived as combining to form gray).
I really can't have those as the last images in this post. Here is a favorite palette.
[Edit 2020-10-07: I had renamed or moved several things I linked to from this post, which broke links. I corrected the links after a reader kindly requested to know where things had gone.]