Manual for Package pgfplots
2D/3D Plots in LATeX, Version 1.18.1
http://sourceforge.net/projects/pgfplots
Related Libraries
5.2ColorBrewer
An extension by Vincent A. Traag and Stefan Pinnow
-
\usepgfplotslibrary{colorbrewer} % LaTeX and plain TeX ¶
-
\usepgfplotslibrary[colorbrewer] % ConTeXt ¶
-
\usetikzlibrary{pgfplots.colorbrewer} % LaTeX and plain TeX ¶
-
\usetikzlibrary[pgfplots.colorbrewer] % ConTeXt ¶
- sequential
-
for ordered data progressing from low to high,
- diverging
-
to highlight changes from a mean value, and
- qualitative
-
where colors have no special order.
This library brings the color schemes created by Cynthia Brewer published at http://colorbrewer2.org/ to PGFPlots. These where originally designed for cartography needs, but are also used in other kind of data visualization in the mean time. The ColorBrewer schemes are divided into the types
They can consist of up to 12 different data classes, i.e. colors, per scheme and are provided as color maps as well as as cycle lists.
5.2.1Usage¶
In the following the available schemes are presented in graphical form as “swatches”.
Color Schemes as “Swatches”
A swatch is a matrix showing all available colors for a specific scheme, and the available color compilations.
Such swatches are read as follows:
-
1. At the top left of the block you find the (short) name of the scheme.
-
2. The following color blocks are the colors the scheme consists of.
-
3. To get the (full) color name, combine the (short) scheme name with a hyphen and a letter of the first row, e.g.
\tikz \fill[color=GnBu-H] (0,0) rectangle (1em,2ex);
which results in .
-
4. To get the full scheme name, which can be used as colormap or cycle list, combine the (short) scheme name with a hyphen and a number of the first column, e.g. cycle list name=GnBu-7.
The special case of using the (short) scheme name only is also provided and is an alias for the full scheme name with the highest number, e.g. scheme name GnBu equals GnBu-9. -
5. The last row shows a continuous color map based on the previous row, that is in the example GnBu-9.
-
6. The rest of the matrix shows the colors used in the corresponding scheme.
Activating Color Schemes
In order to activate a colorbrewer colormap, say, BuGn-5, you have to use the key
This will initialize and select the associated colormap. It will also initialize the associated cycle list (but will not select it). In order to initialize and select the cycle list of name BuGn-5, you have to use the key
cycle list/BuGn-5.
This will initialize and select the associated cycle list. It will also initialize (but not select) the associated colormap.
Note that cycle lists shipped with colorbrewer merely consist of colors. However, a good cycle list typically also comes with markers and perhaps line style variations. In order to combine a pure color-based cycle list with markers, you should make use of the features cycle multi list, cycle multiindex list, and cycle multiindex* list, for example using
Please refer to the reference manual for cycle multiindex* list for details.
5.2.2Sequential Schemes¶
Sequential schemes are useful for ordered data progressing low to high.
5.2.3Diverging Schemes¶
Diverging schemes highlight changes from some mean value.
Note that you can adopt point meta min and point meta max such that the colormap’s mean value fits the data (for example by forcing point meta min=-2 and point meta max=+2).
5.2.4Qualitative Schemes¶
Qualitative schemes are useful if colors have no special order, but should be distinguishable.
5.2.5Interaction with the ColorBrewer website¶
To find a scheme, e.g. the above chosen GnBu-7 on http://colorbrewer2.org/
-
• first select the “Nature of your data” type; in this case “sequential”,
-
• then select the “Number of data classes”, which is 7,
-
• and last select the corresponding scheme in the “Pick a color scheme” section. (This is a bit tricky, because you can only see the name at the top of the lower right corner, where all the colors are listed. When you have selected the right one you should read there “7-class GnBu”. But perhaps it helps when you know that “Gn” stands for green and “Bu” for blue, so you are searching for a scheme going from green to blue, which in this case is the third color scheme in the first row of “Multi-hue”.)
-
• The color names, e.g. GnBu-H, cannot be extracted from the page directly though, because you cannot simply count to the number and replace it with the corresponding letter. This intentionally was avoided, because then one would define the same color multiple times with different names, e.g. GnBu-H 3 times.
-
• If you should need let’s say the 5th color of the scheme GnBu-7 you don’t have to trial and error or have a look at the manual. You can simply extract this color from the corresponding color map via the index of colormap feature, e.g.
\tikz \fill[index of colormap={4 of GnBu-7}] (0,0) rectangle (1em,2ex);
which results in . Note that the index is \(4\) instead of \(5\) because the index starts with \(0\). Note furthermore that you have to invoke \pgfplotsset{colormap/GnBu-7} before using this key.
5.2.6External Examples¶
If you want to see some examples, where Brewer has used her schemes, have a look at https://www.census.gov/population/www/cen2000/atlas/index.html.
-
\usetikzlibrary{colorbrewer} % LaTeX and plain TeX
-
\usetikzlibrary[colorbrewer] % ConTeXt
A library which contains just the color definitions like GnBu-B. Please refer to Section 5.2.1 for a list of available colors.