plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

go.Histogram2dContour does not normalize when using shared coloraxis and coloring='fill'

Open PhilippHa3 opened this issue 1 year ago • 1 comments

Setup: plotly==5.18.0

Bug: When adding two go.Histogram2dContour to a subplot, the colorscale is not normalized, when using a shared coloraxis and setting coloring='fill'. It works when setting coloring='heatmap'.

Dataframes used:

df_a = pd.DataFrame({
    'a':[0,0,1,1],
    'b':[0,1,0,1],
    'c':[0,1,2,3],
    
})

df_b = pd.DataFrame({
    'a':[0,0,1,1],
    'b':[0,1,0,1],
    'c':[10,20,30,40],
    
})

Example coloring='fill': histogram2dContour_fill

Example coloring='heatmap': histogram2dContour_heatmap

Code:

fig = make_subplots(rows=1,cols=2)

fig.add_trace(
            go.Histogram2dContour(
                x=df_a['a'].to_list(),
                y=df_a['b'].to_list(),
                z=df_a['c'].to_list(),
                # contours=dict(coloring="heatmap"),
                contours=dict(coloring="fill"),
                coloraxis="coloraxis",
                showscale=True,
                showlegend=False,
                histfunc='max',
            ),
            row=1,
            col=1
        )

fig.add_trace(
            go.Histogram2dContour(
                x=df_b['a'].to_list(),
                y=df_b['b'].to_list(),
                z=df_b['c'].to_list(),
                # contours=dict(coloring="heatmap"),
                contours=dict(coloring="fill"),
                coloraxis="coloraxis",
                showscale=True,
                showlegend=False,
                histfunc='max',
            ),
            row=1,
            col=2
        )

fig.show()

PhilippHa3 avatar Dec 17 '23 16:12 PhilippHa3

This might be a bug. Thanks for reporting, @PhilippHa3

Here's the full code that reproduces the bug:

import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots


df_a = pd.DataFrame({
    'a': [0, 0, 1, 1],
    'b': [0, 1, 0, 1],
    'c': [0, 1, 2, 3],

})

df_b = pd.DataFrame({
    'a': [0, 0, 1, 1],
    'b': [0, 1, 0, 1],
    'c': [10, 20, 30, 40],

})

fig = make_subplots(rows=1,cols=2)

fig.add_trace(
            go.Histogram2dContour(
                x=df_a['a'].to_list(),
                y=df_a['b'].to_list(),
                z=df_a['c'].to_list(),
                contours=dict(coloring="heatmap"),
                # contours=dict(coloring="fill"),
                coloraxis="coloraxis",
                showscale=True,
                showlegend=False,
                histfunc='max',
            ),
            row=1,
            col=1
        )

fig.add_trace(
            go.Histogram2dContour(
                x=df_b['a'].to_list(),
                y=df_b['b'].to_list(),
                z=df_b['c'].to_list(),
                contours=dict(coloring="heatmap"),
                # contours=dict(coloring="fill"),
                coloraxis="coloraxis",
                showscale=True,
                showlegend=False,
                histfunc='max',
            ),
            row=1,
            col=2
        )

fig.show()

Coding-with-Adam avatar Dec 18 '23 19:12 Coding-with-Adam