Search code examples
matplotlibcolors

Maxwell Color Triangle with Matplotlib


I want to create a Maxwell color triangle

enter image description here

(https://homepages.abdn.ac.uk/npmuseum/article/Maxwell/Legacy/MaxTri.html)

using Matplotlib. I have found code for something similar: http://www.f-legrand.fr/scidoc/docmml/image/niveaux/couleurs/couleurs.html

However, in that case, equal proportions of R, G, and B yield darker colors which is not what I want.

Any ideas are welcome. I am really struggling with this.


Solution

  • Inside Maxwell Triangle: r + g + b = 1.0, it means the center will be RGB(1/3, 1/3, 1/3) ([0.0,1.0] range) which is dark compared to white RGB(1.0,1.0,1.0).

    In order to get white (RGB(1.0,1.0,1.0)) at the center it is possible to multiply RGB values by 3.0: center would be perfectly white but out-of-bound values would be cropped ie RGB(2.0,1.0,1.0) would be displayed as RGB(1.0, 1.0, 1.0).

    RGB values * 3

    Another way is to maximize brightness: RGB(r,g,b) -> 1 / max(r,g,b) * RGB(r, g, b) e.g. RGB(0.2, 0.5, 0.1) -> RGB(0.4, 1.0, 0.2). That way values are never clipped and brightness is maximal.

    RGB * 1 / max(r,g,b)