ContourChart
A surface sampled on a grid, as iso-lines or filled bands. The Contour Chart guide shows every feature on real data; this page is the contract: the function, the shape of its data, the keys style takes, and the constant each parameter accepts.
Function
datachart.charts.ContourChart
ContourChart(
data: ContourDataAttrs | list[ContourDataAttrs],
*,
title: str | None = None,
xlabel: str | None = None,
ylabel: str | None = None,
subtitle: str | list[str | None] | None = None,
emphasis: (
EMPHASIS | str | list[str | None] | None
) = None,
emphasis_rule: EmphasisRuleAttrs | None = None,
figsize: FIG_SIZE | tuple[float, float] | None = None,
xmin: int | float | datetime | None = None,
xmax: int | float | datetime | None = None,
ymin: int | float | None = None,
ymax: int | float | None = None,
show_legend: bool | None = None,
legend: LegendSettingAttrs | None = None,
show_grid: SHOW_GRID | str | bool | None = None,
filled: bool | None = None,
levels: (
CONTOUR_LEVELS | str | int | list[float] | None
) = None,
show_labels: bool | None = None,
show_colorbars: bool | None = None,
aspect_ratio: ASPECT_RATIO | str | None = None,
scalex: SCALE | str | None = None,
scaley: SCALE | str | None = None,
subplots: bool | None = None,
max_cols: int | None = None,
sharex: bool | None = None,
sharey: bool | None = None,
style: (
ContourStyleAttrs
| list[ContourStyleAttrs | None]
| None
) = None,
norm: str | list[str | None] | None = None,
vmin: float | list[float | None] | None = None,
vmax: float | list[float | None] | None = None,
valfmt: (
VALUE_FORMAT | str | list[str | None] | None
) = None,
xticks: (
list[int | float | datetime]
| list[list[int | float | datetime]]
| None
) = None,
xticklabels: list[str] | list[list[str]] | None = None,
xtickrotate: int | list[int | None] | None = None,
yticks: (
list[int | float] | list[list[int | float]] | None
) = None,
yticklabels: list[str] | list[list[str]] | None = None,
ytickrotate: int | list[int | None] | None = None,
xticks_format: (
VALUE_FORMAT | DATE_FORMAT | str | None
) = None,
yticks_format: (
VALUE_FORMAT | DATE_FORMAT | str | None
) = None,
vlines: (
VLineSettingAttrs
| list[VLineSettingAttrs]
| list[
VLineSettingAttrs
| list[VLineSettingAttrs]
| None
]
| None
) = None,
hlines: (
HLineSettingAttrs
| list[HLineSettingAttrs]
| list[
HLineSettingAttrs
| list[HLineSettingAttrs]
| None
]
| None
) = None,
vspans: (
VSpanSettingAttrs
| list[VSpanSettingAttrs]
| list[
VSpanSettingAttrs
| list[VSpanSettingAttrs]
| None
]
| None
) = None,
hspans: (
HSpanSettingAttrs
| list[HSpanSettingAttrs]
| list[
HSpanSettingAttrs
| list[HSpanSettingAttrs]
| None
]
| None
) = None,
colorbar: (
ColorbarSettingAttrs
| list[ColorbarSettingAttrs | None]
| None
) = None,
texts: (
TextSettingAttrs
| list[TextSettingAttrs]
| list[
TextSettingAttrs | list[TextSettingAttrs] | None
]
| None
) = None
) -> plt.Figure
Creates the contour chart.
A contour chart draws a surface sampled on a grid — a loss landscape, a
2-D density, a terrain — as iso-lines of equal value, or as filled bands
between them. Use it to read the shape of a function of two variables:
where its minima and ridges sit and how steeply it changes. Lines overlay
on other charts and on each other; fills stand alone, with an optional
colorbar. For a per-cell view of a matrix use
Heatmap; for the raw points behind a density
use ScatterChart.
Examples:
>>> from datachart.charts import ContourChart
>>> figure = ContourChart(
... data={
... "x": [0, 1, 2],
... "y": [0, 1, 2],
... "z": [
... [0, 1, 4],
... [1, 2, 5],
... [4, 5, 8],
... ],
... },
... title="Basic Contour Chart",
... xlabel="X",
... ylabel="Y"
... )
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The gridded surface(s): a dictionary with the 2-D
TYPE:
|
title
|
The title of the chart.
TYPE:
|
xlabel
|
The x-axis label.
TYPE:
|
ylabel
|
The y-axis label.
TYPE:
|
subtitle
|
The subtitle(s) for individual charts. Used as legend labels.
TYPE:
|
emphasis
|
The emphasis role(s) for individual line contours, aligned
like
TYPE:
|
emphasis_rule
|
A rule that highlights the line contours matching it and mutes
the rest:
TYPE:
|
figsize
|
The size of the figure.
TYPE:
|
xmin
|
The minimum x-axis value.
TYPE:
|
xmax
|
The maximum x-axis value.
TYPE:
|
ymin
|
The minimum y-axis value.
TYPE:
|
ymax
|
The maximum y-axis value.
TYPE:
|
show_legend
|
Whether to show the legend.
TYPE:
|
legend
|
The per-figure legend setting: title, location, column count
and alignment; each field falls back to the theme. See
TYPE:
|
show_grid
|
Which grid lines to show (e.g., "both", "x", "y");
TYPE:
|
filled
|
Whether to fill the bands between the levels (colored by the colormap) instead of drawing iso-lines (in the chart's color).
TYPE:
|
levels
|
Which levels cut the surface: a rule of
TYPE:
|
show_labels
|
Whether to write the level values along the iso-lines.
TYPE:
|
show_colorbars
|
Whether to show the colorbar(s) of filled contours.
TYPE:
|
aspect_ratio
|
The aspect ratio of the axes ("auto" or "equal"). See
TYPE:
|
scalex
|
The x-axis scale (e.g., "log", "linear").
TYPE:
|
scaley
|
The y-axis scale (e.g., "log", "linear").
TYPE:
|
subplots
|
Whether to create separate subplots for each chart.
TYPE:
|
max_cols
|
Maximum number of columns in subplots (when subplots=True).
TYPE:
|
sharex
|
Whether to share the x-axis in subplots.
TYPE:
|
sharey
|
Whether to share the y-axis in subplots.
TYPE:
|
style
|
Style configuration(s) for the contour chart(s).
TYPE:
|
norm
|
Value normalization method(s) of the colormap.
TYPE:
|
vmin
|
Minimum value(s) for normalization.
TYPE:
|
vmax
|
Maximum value(s) for normalization.
TYPE:
|
valfmt
|
Format string(s) for the inline level labels, with the value named
TYPE:
|
xticks
|
Custom x-axis tick positions.
TYPE:
|
xticklabels
|
Custom x-axis tick labels.
TYPE:
|
xtickrotate
|
Rotation angle for x-axis tick labels.
TYPE:
|
yticks
|
Custom y-axis tick positions.
TYPE:
|
yticklabels
|
Custom y-axis tick labels.
TYPE:
|
ytickrotate
|
Rotation angle for y-axis tick labels.
TYPE:
|
xticks_format
|
The x-axis tick label format: a
TYPE:
|
yticks_format
|
The y-axis tick label format, as
TYPE:
|
vlines
|
Vertical line(s) to plot.
TYPE:
|
hlines
|
Horizontal line(s) to plot.
TYPE:
|
vspans
|
Vertical reference band(s) to shade, between two x positions.
TYPE:
|
hspans
|
Horizontal reference band(s) to shade, between two y positions.
TYPE:
|
colorbar
|
The colorbar setting(s): label, location, tick format, and tick
positions. See
TYPE:
|
texts
|
Text annotation(s) to draw.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
plt.Figure
|
The figure containing the contour chart. |
Data
Each record in data is a ContourDataAttrs.
datachart.typings.ContourDataAttrs
Bases: TypedDict
The data attributes for the contour chart.
| ATTRIBUTE | DESCRIPTION |
|---|---|
x |
The x-axis values, one per column of
TYPE:
|
y |
The y-axis values, one per row of
TYPE:
|
z |
The 2-D grid of surface values, one row per
TYPE:
|
Style
style takes the keys of ContourStyleAttrs. The chart also reads the shared groups it draws: reference lines (VLineStyleAttrs and HLineStyleAttrs), reference bands (VSpanStyleAttrs and HSpanStyleAttrs) and text annotations (TextStyleAttrs). Every key falls back to the theme, so the same keys set the default look through config.
datachart.typings.ContourStyleAttrs
Bases: TypedDict
The typing for the contour chart style.
| ATTRIBUTE | DESCRIPTION |
|---|---|
plot_contour_color |
The color of the iso-lines;
TYPE:
|
plot_contour_cmap |
The colormap of the filled bands (palette name, single color, list of hex colors, or colormap);
TYPE:
|
plot_contour_line_width |
The width of the iso-lines;
TYPE:
|
plot_contour_line_style |
The style of the iso-lines.
TYPE:
|
plot_contour_alpha |
The alpha value of the contour.
TYPE:
|
plot_contour_zorder |
The z-order of the contour.
TYPE:
|
plot_contour_label_font_size |
The font size of the inline level labels;
TYPE:
|
plot_contour_label_font_color |
The color of the inline level labels;
TYPE:
|
Constants
The parameters that accept a constant, with the class in datachart.constants that lists its values.
| Parameter | Constant |
|---|---|
levels |
CONTOUR_LEVELS |
emphasis |
EMPHASIS |
figsize |
FIG_SIZE |
legend={"location": ..., "alignment": ...} |
LEGEND_LOCATION, LEGEND_ALIGN |
show_grid |
SHOW_GRID |
aspect_ratio |
ASPECT_RATIO |
scalex |
SCALE |
scaley |
SCALE |
norm |
NORMALIZE |
valfmt |
VALUE_FORMAT |
xticks_format |
VALUE_FORMAT, DATE_FORMAT |
yticks_format |
VALUE_FORMAT, DATE_FORMAT |
colorbar={"location": ..., "format": ..., "orientation": ...} |
COLORBAR_LOCATION, VALUE_FORMAT, ORIENTATION |