mahdilamb / colormap

A Java package for generating and using linear and categorical colormaps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Java (JDK11) Java (JDK8)

Colormap

Colormap is a Java package for creating and using colormaps. It includes many "reference" colormaps, including those from Matplotlib , Tableau and other sources (see credits).

Overview

  • The main access to the colormaps is through net.mahdilamb.colormap.Colormaps. This includes a lot of wrapper classes and the ability to list the reference colormaps Colormaps.named().
  • The wrapper classes include a reversed colormap (Colormaps.reversedColormap()), as well as a "fluid" colormap Colormaps.fluidColormap(). A fluid colormap is not, unlike the reference colormaps, limited to the range 0-1. Instead, a fluid colormap can autoscale, or be clamped between a min and max value (see net.mahdilamb.colormap.FluidColormap for more information). Fluid colormaps can also have the backing colormap changed.

Using reference colormaps

Reference colormaps can either be accessed through Colormaps.get(String), which can take a String such as "sequential.viridis", "viridis" or "sequential.viridis.reversed". Alternatively, they can be accessed using a class path embedded in the Colormaps class e.g. Colormaps.Sequential.Viridis() (and then, for exampled made fluid Colormaps.fluidColormap(Colormaps.Sequential.Viridis())).

Creating colormaps

Colormaps can be created in two ways either using a builder Colormaps.buildSequential() and Colormaps.buildQualitative(), or by extending net.mahdilamb.colormap.SequentialColormap and net.mahdilamb.colormap.QualitativeColormap. Reference colormaps are created by the latter approach.

Fluid colormaps example

As the fluid colormaps are autoranging, they fire an even when the color is changed. The below example shows how this might be done using a lambda expression. The original value is 0, but this changes when a new color is requested from the colormap, and the range is changed, and a new event is triggered.

import net.mahdilamb.colormap.Colormaps;
import net.mahdilamb.colormap.FluidColormap;

public class Test {
    public static void main(final String[] args) {
        final FluidColormap viridis = Colormaps.fluidColormap(Colormaps.get("Viridis"));
        viridis.get(0f, color -> {
            System.out.println(color);
        });

        viridis.get(-1);
    }
}

Color

The colormap package includes a Colors utility class net.mahdilamb.colormap.Colors. It holds constants for the colors specified in CSS4, AWT and Tableau.

Developer note

It is possible to also include the xkcd colors. The addition of the colors is done automatically from text files in src\test\java\net\mahdilamb\colormap\reflect\InsertColors.java. Uncomment the line referring to the xkcd file parsing and add an extra method in the Color class.

public static Color getXKCD(String name) {
    return get(ColorType.XKCD, name);
}

Maven

The package can be imported from maven.

Reference colormaps

Category ColorMap Sample Source
Cyclic Edge edge Paraview
Cyclic HSV hsv
Cyclic IceFire icefire Paraview
Cyclic MRYBM mrybm CET
Cyclic MYGBM mygbm CET
Cyclic Phase phase CMOcean
Cyclic Twilight twilight matplotlib
Cyclic TwilightShifted twilightshifted matplotlib
Diverging ArmyRose armyrose CARTO
Diverging Balance balance CMOcean
Diverging BentCoolWarm bentcoolwarm Kenneth Moreland
Diverging BrBG brbg ColorBrewer
Diverging Curl curl CMOcean
Diverging Delta delta CMOcean
Diverging Diff diff CMOcean
Diverging Earth earth CARTO
Diverging Fall fall CARTO
Diverging Geyser geyser CARTO
Diverging Oxy oxy CMOcean
Diverging Picnic picnic Plotly
Diverging PiYG piyg ColorBrewer
Diverging Portland portland Plotly
Diverging PRGn prgn ColorBrewer
Diverging PuOr puor ColorBrewer
Diverging RdBu rdbu ColorBrewer
Diverging RdGy rdgy ColorBrewer
Diverging RdYlBu rdylbu ColorBrewer
Diverging RdYlGn rdylgn ColorBrewer
Diverging SmoothCoolWarm smoothcoolwarm Kenneth Moreland
Diverging Spectral spectral ColorBrewer
Diverging TealRose tealrose CARTO
Diverging Temps temps CARTO
Diverging Topo topo CMOcean
Diverging Tropic tropic CARTO
Qualitative Accent accent ColorBrewer
Qualitative Alphabet alphabet Polychrome
Qualitative Antique antique CARTO
Qualitative Bold bold CARTO
Qualitative D3 d3 d3.js
Qualitative Dark2 dark2 ColorBrewer
Qualitative Dark24 dark24 Polychrome
Qualitative G10 g10 Plotly
Qualitative Light24 light24 Polychrome
Qualitative Paired paired ColorBrewer
Qualitative Pastel pastel CARTO
Qualitative Pastel1 pastel1 ColorBrewer
Qualitative Pastel2 pastel2 ColorBrewer
Qualitative Plotly plotly Plotly
Qualitative Prism prism CARTO
Qualitative Safe safe CARTO
Qualitative Set1 set1 ColorBrewer
Qualitative Set2 set2 ColorBrewer
Qualitative Set3 set3 ColorBrewer
Qualitative T10 t10 Plotly
Qualitative Tab10 tab10 Tableau
Qualitative Tab20 tab20 Tableau
Qualitative Tab20b tab20b Tableau
Qualitative Tab20c tab20c Tableau
Qualitative Vivid vivid CARTO
Sequential AgGrnYl aggrnyl Plotly
Sequential AgSunset agsunset Plotly
Sequential Algae algae CMOcean
Sequential Amp amp CMOcean
Sequential BlackBody blackbody Kenneth Moreland
Sequential BlackbodyAlt blackbodyalt Plotly
Sequential BlackBodyExtended blackbodyextended Kenneth Moreland
Sequential Blues blues ColorBrewer
Sequential BluGrn blugrn CARTO
Sequential BluYl bluyl CARTO
Sequential BrwnYl brwnyl CARTO
Sequential BuGn bugn ColorBrewer
Sequential BuPu bupu ColorBrewer
Sequential Burg burg CARTO
Sequential BurgYl burgyl CARTO
Sequential Cividis cividis matplotlib
Sequential CubeYF cubeyf MyCarta
Sequential DarkMint darkmint CARTO
Sequential Deep deep CMOcean
Sequential Dense dense CMOcean
Sequential Electric electric Plotly
Sequential Emrld emrld CARTO
Sequential GnBu gnbu ColorBrewer
Sequential Gray gray CMOcean
Sequential Greens greens ColorBrewer
Sequential Greys greys ColorBrewer
Sequential Haline haline CMOcean
Sequential Hesperia hesperia Peter Karpov
Sequential Hot hot Plotly
Sequential Ice ice CMOcean
Sequential Inferno inferno matplotlib
Sequential Jet jet
Sequential Kindlmann kindlmann Kindlmann et al.
Sequential KindlmannExtended kindlmannextended Kindlmann et al.
Sequential KovesiBGYW kovesibgyw CET
Sequential KovesiKRYW kovesikryw CET
Sequential Lacerta lacerta Peter Karpov
Sequential Laguna laguna Peter Karpov
Sequential Magenta magenta CARTO
Sequential Magma magma matplotlib
Sequential Matter matter CMOcean
Sequential Mint mint CARTO
Sequential Oranges oranges ColorBrewer
Sequential OrRd orrd ColorBrewer
Sequential OrYel oryel CARTO
Sequential Peach peach CARTO
Sequential PinkYl pinkyl CARTO
Sequential Plasma plasma matplotlib
Sequential PlasmaModified plasmamodified Peter Karpov
Sequential Plotly3 plotly3 Plotly
Sequential PuBu pubu ColorBrewer
Sequential PuBuGn pubugn ColorBrewer
Sequential PuRd purd ColorBrewer
Sequential Purp purp CARTO
Sequential Purples purples ColorBrewer
Sequential PurpOr purpor CARTO
Sequential Rain rain CMOcean
Sequential RdPu rdpu ColorBrewer
Sequential RedOr redor CARTO
Sequential Reds reds ColorBrewer
Sequential Solar solar CMOcean
Sequential Speed speed CMOcean
Sequential Sunset sunset CARTO
Sequential SunsetDark sunsetdark CARTO
Sequential Tarn tarn CMOcean
Sequential Teal teal CARTO
Sequential TealGrn tealgrn CARTO
Sequential Tempo tempo CMOcean
Sequential Thermal thermal CMOcean
Sequential Turbid turbid CMOcean
Sequential Turbo turbo Google AI
Sequential Viridis viridis matplotlib
Sequential YlGn ylgn ColorBrewer
Sequential YlGnBu ylgnbu ColorBrewer
Sequential YlOrBr ylorbr ColorBrewer
Sequential YlOrRd ylorrd ColorBrewer

Colormap credits

About

A Java package for generating and using linear and categorical colormaps.

License:Apache License 2.0


Languages

Language:Java 100.0%