Removing background and using a colorscale with Plotly graph objects Funnel

Viewed 88

I am trying to create a funnel using Plotly graph objects and I need the color to go from light to darker tones of the same color - for example from light red to dark red. I tried using the colorscale property, but all it returns is an entirely black funnel.

Another problem that I have is that I want to remove the background, but I have not found a way to do that either.

Here is what I tried last:

data = dict(
    number=[20000, 10000, 5000, 2500, 1110],
    stage=["Leads", "MQL", "SQL", "Opportunity", "Orders"])
df = pd.DataFrame(data)

fig = go.Figure(go.Funnel(y=df.number,
                          x=df.stage,
                          textposition="inside",
                          textinfo="value+percent initial",
                          orientation='v',
                          marker={"color": [[0, 1]],
                                  "colorscale": 'Hot',
                                  "colorbar": {"bgcolor": None}}
                          ))

I have read the documentation page multiple times and it does not become any clearer to me how these properties are to be used...

Any help would be greatly appreciated, thank you!

1 Answers

I am not familiar with this type of graph as I do not usually use it, but referring to the official reference, it seems that colors are specified by color name, not by number. The colors are not in the desired order, but you may change the order to your own preference. And to eliminate the background, you can set the template to none. See this for the official reference.

import plotly.graph_objects as go
import pandas as pd

data = dict(
    number=[20000, 10000, 5000, 2500, 1110],
    stage=["Leads", "MQL", "SQL", "Opportunity", "Orders"])
df = pd.DataFrame(data)

fig = go.Figure(go.Funnel(y=df.number,
                          x=df.stage,
                          textposition="inside",
                          textinfo="value+percent initial",
                          orientation='v',
                          marker={"color": ['#dc143c','#ff0000','#ff4500','#FF6347','#ff7F50'],
                                  "colorscale": 'Hot',
                                  "colorbar": {"bgcolor": None}}
                          ))
fig.update_layout(template=None)
fig.show()

enter image description here

Related