ForColormap, a Fortran library for colormaps 🌈

I am glad to see so much color in the Discourse! It seems color has the power to generate some joy in this world. And I am discovering how a simple colorbar can be aesthetic.

@Ali has joined the development: he refactored and improved the code, and added four matplotlib colormaps (“magma”, “inferno”,“plasma”, “viridis”). ForColormap is now using its ForImage project as a dependency: it was an interesting test to see how fpm manages dependencies and sub-dependencies when we use a library (no problem if you create a project with ForImage and ForColormap as dependencies, although ForColormap is also itself using ForImage).

And @alozada is working on a logo.

1 Like

Yes, there are five cyclic maps as you can see here at the bottom right:

Well, thanks for teaching (stupid) me that the O at the end of the colormap names means they are cyclic :sweat_smile:. With the above picture, my neurons suddenly flashed…

More about these cyclic maps:

If I understand correctly, those “scientific colour maps” are mostly useful for contour plots.

What about many series of xy plots or stacked bar plots? In such cases it is not necessary to have smooth colour transitions but, on the contrary, a clear distinction between unrelated series or bars is expected. Have colour series been developed also for such use cases?

2 Likes

In the middle of the above picture you will see “Categorical palettes”, which may be what you need. Their names are ended by a “S”, for example lipariS:
image

They have 100 levels.

2 Likes

@Ali has now successfully imported the missing discrete Scientific Colour Maps. They are generally available in four versions with 10, 25, 50 or 100 levels. For example, this is the roma10 colormap:
image

If my count is exact, we now have 235 colormaps in the project.

6 Likes

The building of such categorical palettes is described in this Fabio’s talk at this point:

Seminar talk by Fabio Crameri about the scientific use of colour in science communication for the University of Oslo GeoHyd seminar.

2 Likes

:rainbow: ForColormap 0.9 was just released after nearly 5 months’ work and 162 commits. Most new code and functionalities were written by @Ali, the CMake (>=3.24) build system and its GitHub CI workflow by jchristopherson, and the logo by @alozada. And @Ali also added CI workflows for fpm testing and FORD documentation. ForColormap is now using his ForImage project as a fpm (and CMake) dependency for writing PPM files (and ForColormap will later benefit from its image manipulating functions). Among novelties listed in the CHANGELOG, we can cite:

  • a colorbar() method to write a PPM file with the colorbar of a colormap,
  • a reverse() method to reverse a colormap,
  • a shift() method to apply a circular shift to a colormap,
  • methods create_lagrange() and create_bezier() to create a colormap from continuous interpolation of control colors,
  • an extract() method to extract a discrete colormap from a continuous colormap,
  • introspection via the src/colormaps_info.f90 module,
  • the FORD documentation https://vmagnin.github.io/forcolormap/,
  • a ForColormap PDF manual showing all the available colormaps, and a web page to help users choose a colormap,
  • new examples,
  • a gallery/ directory with screenshots of simulations using ForColormap,
  • a few new colormaps, especially the “magma”, “inferno”,“plasma” and “viridis” matplotlib colormaps and a “black_body” colormap.

I have added a new example in the gtk-fortran-extra repository. It uses ForColormap and creates a movie with Turing patterns (using the Reaction Diffusion Gray-Scott Algorithm), displayed with various colormaps:

(You can easily adapt that model to your favorite graphical library, the scientific part is in the scientific_computing.f90 file and references are provided in the README.)

Feedback is welcome. If you use ForColormap with other graphical C libraries, we are especially interested by the way you pass the RGB values to these libraries. Feedback by Windows users will also be useful, and also if you test ForColormap with compilers other than GFortran and Intel.

The main goal of the future 1.0 version will be to offer a library with a stable API, to improve the FORD documentation and to follow the Diátaxis documentation framework (but probably new functionalities will also be added as ideas are numerous, more than our available working hours).

And if you are looking for a fun project with ForColormap, I suggest writing a Fortran version of Lenia (see also Wikipedia page), a continuous generalization of Conway’s Game of Life. I have found no Fortran Lenia on GitHub.

17 Likes

Just a remark on a fix I have just pushed, as it could be useful for other fpm projects:

in the fpm.toml, I had written:

name = "ForColormap"

and in an example using ForColormap as a dependency:

[dependencies]
forcolormap = {git = "https://github.com/vmagnin/forcolormap.git"}

and obtained that error

$ fpm build
<ERROR> *cmd_build* Model error: Dependency name 'ForColormap' found,
but expected 'forcolormap' instead
STOP 1

So, fpm dependencies are case sensitive. To avoid any problem, I have updated the manifest of ForColormap:

name = "forcolormap"

I think it’s better to use lower case in manifests to keep things simple. But I still use ForColormap in my texts for human beings (they can adapt to any case!, which could be a definition of intelligence), because I like it.

1 Like