Skip to content
Correlation Plot

Correlation Plot

A correlation plot: one bubble per cell of a correlation matrix, sized and colored by strength, for spotting which variable pairs move together across a dataset too large to read as a table of numbers.

Correlation Plot

Usage

from dataviz import corrplot
from dataviz import save

def main() raises:
    # Illustrative correlations across electric-vehicle specifications.
    # Six variables reveal clusters and tradeoffs that a tiny matrix hides.
    var variables: List[String] = [
        "Price", "Range", "Efficiency", "Charge time", "Cargo", "0-60 time",
    ]
    var matrix: List[List[Float64]] = [
        [1.0, 0.72, 0.18, -0.25, 0.48, -0.63],
        [0.72, 1.0, -0.22, 0.35, 0.51, -0.40],
        [0.18, -0.22, 1.0, -0.44, -0.58, 0.36],
        [-0.25, 0.35, -0.44, 1.0, 0.18, 0.22],
        [0.48, 0.51, -0.58, 0.18, 1.0, -0.15],
        [-0.63, -0.40, 0.36, 0.22, -0.15, 1.0],
    ]

    var c = corrplot(
        variables,
        matrix,
        layout="upper",
        diag=False,
        title="Illustrative EV Metric Correlations",
    )
    save(c, "docs/src/examples/out_corrplot.svg")

See Data shapes for shared input conventions.

Args:

  • variables: One row and one column per entry – matrix must be this length square.
  • matrix: The square pairwise-correlation matrix, each value in [-1.0, 1.0].
  • layout: Which triangle of matrix to draw – "full" (the default), "lower", or "upper".
  • diag: Whether to draw the diagonal cells (variables[i] against itself); defaults to True.
  • labels: Whether to draw variables’ names along the axes; defaults to True.
  • bubble_fraction: Each bubble’s maximum radius as a fraction of the cell’s smaller dimension; defaults to 0.42.
  • theme: Full styling knobs beyond this function’s own parameters (colors, margins, fonts, gridlines, …) – see Theme’s docstring.
  • width: Pixel width of the returned Plot (.size()).
  • height: Pixel height of the returned Plot (.size()).
  • title: The chart’s title, shown above the plot.
  • subtitle: A secondary line shown under the title.
  • x_title: The x-axis caption.
  • y_title: The y-axis caption.

Related

Related charts: Calendar Heatmap · Punchcard

Relevant API: corrplot