Skip to content

template.layout.colorscale not applied to heatmap unless autocolorscale is True #3829

@jonmmease

Description

@jonmmease

Consider a heatmap trace with a template that specifies a global default colorscale:

CodePen: https://codepen.io/jonmmease/pen/XQvbge?editors=1010

var fig = {
  "data": [
    {
      "type": "heatmap",
      "x": [1, 2, 3, 4, 5, 6, 7, 8, 9],
      "y": [1, 2, 3, 4, 5, 6, 7, 8, 9],
      "z": [1, 2, 3, 4, 5, 6, 7, 8, 9],
    }
  ],
  "layout": {
    "template": {
      "layout": {
        "colorscale": {
          "sequential": "Cividis"
        }
      }
    },
    "title": {
      "text": "Colorscale templating test"
    }
  }
}

Plotly.newPlot('myDiv', fig, {showSendToCloud: true});

newplot-7

This template colorscale is not applied. If the template's heatmap autocolorscale property is set to true then the colorscale is applied.

var fig = {
  "data": [
    {
      "type": "heatmap",
      "x": [1, 2, 3, 4, 5, 6, 7, 8, 9],
      "y": [1, 2, 3, 4, 5, 6, 7, 8, 9],
      "z": [1, 2, 3, 4, 5, 6, 7, 8, 9],
      // "colorscale": "Viridis"
    }
  ],
  "layout": {
    "template": {
      "data": {
        "heatmap": [
          {"autocolorscale": true}
        ]
      },
      "layout": {
        "colorscale": {
          "sequential": "Cividis"
        }
      }
    },
    "title": {
      "text": "Colorscale templating test"
    }
  }
}

Plotly.newPlot('myDiv', fig, {showSendToCloud: true});

newplot-8

but in this case, the colorscale provided in the heatmap trace is ignored.

var fig = {
  "data": [
    {
      "type": "heatmap",
      "x": [1, 2, 3, 4, 5, 6, 7, 8, 9],
      "y": [1, 2, 3, 4, 5, 6, 7, 8, 9],
      "z": [1, 2, 3, 4, 5, 6, 7, 8, 9],
      "colorscale": "Viridis"
    }
  ],
  "layout": {
    "template": {
      "data": {
        "heatmap": [
          {"autocolorscale": true}
        ]
      },
      "layout": {
        "colorscale": {
          "sequential": "Cividis"
        }
      }
    },
    "title": {
      "text": "Colorscale templating test"
    }
  }
}


Plotly.newPlot('myDiv', fig, {showSendToCloud: true});

newplot-8

I don't fully understand the intended behavior of autocolorscale in the case of templates, but I think we need some way to specify a default global colorscale in the template and then be able to override it in the trace without explicitly specifying autocolorscale in the trace.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions