Contour plots
Contour plots have several uses:
- Visualizing 3D data: A contour plot projects the "height" (z-value) of a 3D surface onto the x-y plane.
- Constant value lines: Each line on the plot represents all the points (x, y) that produce the same output value (z).
- Slope and steepness: The distance between the contour lines shows how fast the function's value is changing. Lines that are close together represent a steep slope, while lines that are far apart represent a more gradual slope.
- Color and height: Colors can be used to indicate different height ranges, with different colors representing higher or lower values, providing another visual cue to the function's behavior.
Parameters
- data
List[List[number]], DataFrame, Series
In addition to all of the standard parameters the following apply to contour plots.
Data
Data is provided to a contour plot as an array of numbers in one of several formats. In Python, or inline in Markdown, the base format is a list of lists of numbers, as follows, where volcano.json looks like:
json
[
[103, 104, 104, 105, 105, ... 94, 94, 94, 94, 94, 94],
[104, 104, 105, 105, 106, ... 95, 94, 94, 94, 94, 94],
[104, 105, 105, 106, 106, ... 95, 94, 94, 94, 94, 94],
...
]html
<contour
path='data/volcano/volcano.json'
width=696
height=488
colors='Spectral_r'
n_colors=20
>
</contour>all of which produce the following:
In Python any of the following is also accepted, as well as the equivalents in FireDucks or Polars:
python
import doodl
import numpy as np
a = np.array([
[0, 10, 20, 30, 20],
[10, 20, 30, 40, 30],
[20, 30, 40, 50, 40],
[10, 20, 30, 40, 30],
[0, 10, 20, 30, 20]
])
doodl.contour(data=a)The n_colors parameter is of particular interest with contour plots. The number of colors chosen determines the number of lines of points with equal value on the plot. The followiing three plots have 10, 20 and 100 for n_colors, respectively: