Skip to content

Allow at most one heatmap trace per figure #101

Closed

Description

@jvdd

Problem

A figure can hold more than one heatmap-like trace (histogram2d, geo_histogram2d, corr_heatmap). Figure.to_spec() then requires them to share the same color_scale, color_range and color_norm (_validate_heatmap_styles in flexviz/figure.py), because the renderers treat the heatmap color control as figure-level.

That rule does not make the figure readable:

  • Each trace draws its own colorbar, at the same place. Reproduced on main (f0b8e7c) with two add_geo_histogram2d traces in one figure: two colorbars, with the tick labels on top of each other.
  • With color_range="auto", each trace has its own range, so two traces with the same style still get two different colorbars.
  • A heatmap is opaque, so the second trace hides the first wherever they overlap.

No test, example or doc uses two heatmaps in one figure, except the tests of the style check.

Proposal

Allow at most one heatmap-like trace per figure:

  • Figure.to_spec() raises when a figure holds more than one. This check replaces _validate_heatmap_styles and _effective_heatmap_style, including the geo_histogram2d part that PR feat(heatmap): add color_norm with a log option to histogram2d and geo_histogram2d #95 adds.
  • A heatmap together with other traces stays allowed, for example a line over a histogram2d, or a geo_line over a geo_histogram2d.
  • Update Architecture.md, which describes the style rule, and add a CHANGELOG entry. This is a breaking change, which the pre-1.0 policy permits.

Tests

Replace the style tests in tests/test_spec.py (TestFigureHeatmapValidation) with one test per heatmap type that checks that a second heatmap in one figure raises, and one test that a heatmap with a line still builds.

Activity

  1. added
    enhancement
    on Sep 27, 2026
  2. jvdd commented on Sep 29, 2026

    @jvdd
    ContributorAuthor

    Fixed by #112.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions