Skip to content

Enable logscale Colorbar#7894

Open
bmaranville wants to merge 8 commits into
plotly:masterfrom
bmaranville:colorbar-logscale
Open

Enable logscale Colorbar#7894
bmaranville wants to merge 8 commits into
plotly:masterfrom
bmaranville:colorbar-logscale

Conversation

@bmaranville

@bmaranville bmaranville commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Implement logscale colorbars natively

Motivation

This feature has been requested a number of times (see #7376 and https://community.plotly.com/t/logarithmic-coloraxis-in-heatmaps-not-working-as-documented/90650/5?u=matinh, for example) and our organization uses logarithmic scaling almost exclusively as the default scale for colormaps for heatmap plots, but it is currently awkward to have to manually set tick labels as suggested in the docs here:
https://plotly.com/python/colorscales/#customizing-tick-text-on-logarithmic-color-bars

Implementation

This PR

  • modifies attribute colorbar.type to be an enum with values ['linear', 'log'], defaulting to 'linear'
  • adds scaling to the range of the colorbar when 'log' is the type
  • adds tests for
    • validation of new attribute
    • proper tick labels in 'log' mode
    • proper color mappings, including for out-of-range (e.g. negative)

Note
this PR was prepared with the assistance of Gemini AI (but audited completely by the human me). The AI was particularly helpful in writing tests.

With this PR, the following trace:

{
  "type": "heatmap",
  "z": [
    [
      1,
      3.1622776601683795,
      10,
      31.622776601683793,
      100,
      316.22776601683796,
      1000
    ],
    [
      3.1622776601683795,
      10,
      31.622776601683793,
      100,
      316.22776601683796,
      1000,
      3162.2776601683795
    ],
    [
      10,
      31.622776601683793,
      100,
      316.22776601683796,
      1000,
      3162.2776601683795,
      10000
    ],
    [
      31.622776601683793,
      100,
      316.22776601683796,
      1000,
      3162.2776601683795,
      10000,
      31622.776601683792
    ],
    [
      100,
      316.22776601683796,
      1000,
      3162.2776601683795,
      10000,
      31622.776601683792,
      100000
    ],
    [
      316.22776601683796,
      1000,
      3162.2776601683795,
      10000,
      31622.776601683792,
      100000,
      316227.7660168379
    ],
    [
      1000,
      3162.2776601683795,
      10000,
      31622.776601683792,
      100000,
      316227.7660168379,
      1000000
    ]
  ],
  "colorscale": "Viridis",
  "colorbar": {
    "type": "log",
    "title": "Log Scale",
    "tickmode": "auto"
  }
}

renders like this:
image

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant