Individual Contour Levels Configuration
The last example exposed a problem: the contour levels are automatically determined. Chosen levels are automatically mapped to colors in the current colormap. The last level at 6000 is the highest value among the contour levels. It maps to the last entry in the Colorcube map – which unfortunately turns out to be white. Hence, that contour line is hardly visible against the white background.
Several options exist to handle that situation:
- Altering the colormap. Set the highest value to some other color which is better visible (See: Managing Colormaps).
- Use individually configured contour levels and specify individual colors for each level. This option will be described next.
Contour plots consist out of individual contour levels. Each level corresponds to a specific data value. Similar to the method of finding ‘nice numbers’ for axis objects, contour plots try to find nice level values automatically – depending on the data values provided.
In the terrain example, the lowest data value is -23, the highest value is 6005. Contour creates 7 levels by default, starting at 0 and increasing equally spaced in steps of 1000.
Every contour level creates an arbitrary number of lines for the corresponding data level. The level value and the label text are automatically chosen. Also, the color of the line is determined by mapping the level value with the current colormap of the contour. All other style settings are taken from ContourLevel.Default: line width, dash style, label color and label visibility.
Individual level style definitions can be provided to the constructor of ContourPlot. As soon as at least one contour level has been specified manually, it will affect the creation of all level lines by cycling through the predefined levels. In the next example 3 levels are given to the constructor of ContourPlot. The contour, however, will still create 7 levels (see below to learn how to control this number). For every new level, the settings from that predefined level are taken, which corresponds to the index of the new level modulus the number of predefined levels. The 4th level corresponds to the 1st predefined level, the 5th level to the 2nd and the 7th level to the 1st and so on.
Only those settings are taken for a contour level, which have been specified by the user. In the example, the first contour level does only specify the line width to be 2. All other settings are still taken from the ContourlLevel.Default. For the 3rd contour level a text was given. This will override the default setting which is to derive the text from the value. The explicit text will instead be used on every 3rd contour level.
Let’s summarize the effect of the specification of 3 predefined contour levels in the example above: Still 7 levels are created. The level values are automatically determined; styles are taken from specified settings in the 3 predefined level parameters in a cyclic manner. Therefore, styles are repeated for every 3 contour levels. Every 1st and 2nd level is drawn with a line width of 2; every second level does not render its label. Every 3rd level is drawn with a thin dashed line and a fixed, red label text instead of the level number.