Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templates overwrite colorscale property of traces. #1454

Closed
SaschaJust opened this issue Mar 6, 2019 · 3 comments · Fixed by #1549
Closed

Templates overwrite colorscale property of traces. #1454

SaschaJust opened this issue Mar 6, 2019 · 3 comments · Fixed by #1549
Labels
bug something broken

Comments

@SaschaJust
Copy link

Hi,

first of all, thank you for introducing template support to plotly.

As far as I understand, template settings should only "replace" default values but never overwrite explicit properties of a plot. However, when using colorscale in heatmaps, the colorscale is always overwritten by the template, no matter if it's specified by alias or as a list.

Consider the following example:

import plotly.graph_objs as go
import plotly.offline as py
from plotly import __version__ as V
py.init_notebook_mode(connected=True)

print(V)

trace = go.Heatmap(
    x = list(range(1,10)),
    y = list(range(1,10)),
    z = list(range(1,10)),
    colorscale = [[0, 'rgb(255,0,0)'], [1, 'rgb(0,255,0)']]
)

layout = go.Layout(
    title = 'Colorscale templating test',
    template = 'ggplot2'
)

fig = go.Figure([trace], layout)

py.iplot(fig)

Result

In this case, the ggplot2 theme's colorscale will be used rather the one explicitly specified in the trace.

@jonmmease
Copy link
Contributor

jonmmease commented Mar 7, 2019

Hi @SaschaJust ,

Glad you're enjoying templates and thanks for the report. It looks like the issue is that the templates set autocolorscale to True which overrides the explicit colorscale. It will take a little digging to figure out whether the issue is with the plotly.py template or with the plotly.js template engine.

In the meantime, you can set autocolorscale to False in your heatmap definition

import plotly.graph_objs as go
import plotly.offline as py
from plotly import __version__ as V
py.init_notebook_mode(connected=True)

print(V)

trace = go.Heatmap(
    x = list(range(1,10)),
    y = list(range(1,10)),
    z = list(range(1,10)),
    colorscale = 'Viridis',
    autocolorscale = False
)

layout = go.Layout(
    title = 'Colorscale templating test',
    template = 'ggplot2'
)

fig = go.Figure([trace], layout)

py.iplot(fig)

newplot 11

@jonmmease jonmmease added the bug something broken label Mar 7, 2019
@SaschaJust
Copy link
Author

Hi @jonmmease,

thanks for getting back to me so quickly. That workaround does just fine.

@SaschaJust
Copy link
Author

Just to confirm: tested with the 3.9.0 rc and works as expected.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants