plotlyplotly-pythontreemapplotly-express

Treemap in plotly does not give unique color


I have a treemap like this:

I am getting same colors for new-required-request-property and response-body-type-changed and same for the one's in orange at the bottom. I need distinct colors for every type.

This is my code for the treemap:

import plotly.express as px
import plotly.graph_objects as go
import numpy as np
import plotly.offline as offline


fig = px.treemap(df5, path=['content'],values='count', color='content', color_discrete_sequence=px.colors.qualitative.Pastel, width = 1500,
    height = 800, title='Top 15 Types of Breaking Changes')

fig.update_traces(textinfo='label+value')
fig.update_layout(margin = dict(t=50, l=35, r=25, b=25), template='ggplot2',font=dict(size=20, family='Serif'), paper_bgcolor='rgba(233,233,233,100)')

fig.show()

I am not sure where I am going wrong, any help with this would be greatly appreciated.


Solution

  • This is occurring because you have 15 unique content values, but the discrete color sequence you chose Pastel only has 11 unique values. You can see a nice diagram of all the possible discrete color sequences in the documentation.

    To get around this, you can choose a discrete color sequence with > 15 unique values such as Dark24 and you should have unique colors for your treemap.

    fig = px.treemap(df5, path=['content'],values='count', color='content', color_discrete_sequence=px.colors.qualitative.Dark24, width = 1500,
        height = 800, title='Top 15 Types of Breaking Changes')