Open
Description
import plotly.express as px
import numpy as np
df = px.data.gapminder().query("year == 2007")
fig = px.treemap(df, path=[px.Constant("world"), 'continent', 'country'], values='pop',
color='lifeExp', hover_data=['iso_alpha'],
color_continuous_scale=[(0, 'red'), (0.4, 'yellow'), (1.0, 'green')],
color_continuous_midpoint=np.average(df['lifeExp'], weights=df['pop']))
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
fig.show()
This gives me the result I want.
However, something like:
color_continuous_scale=[(0, 'red'), (0.4, 'yellow'), (0.8, 'green')],
creates a whole separate treemap.
This fixes the issue:
color_continuous_scale=[(0, 'red'), (0.4, 'yellow'), (0.8, 'green')], (1.0, 'green')],
I'm not sure if there's anything to even technically "fix" here, but it was expected behaviour that I didn't get.