Plotly Treemap Returns Blank

Viewed 999

please see the fast fully contained colab example https://colab.research.google.com/drive/1lzaw1AmYeJtrcPBxcPCZPyeiACvv4U1C?usp=sharing

input:

%%capture
!pip install --upgrade plotly
import pandas as pd 
final = pd.read_csv("https://raw.githubusercontent.com/firmai/random-assets-two/master/test/file.csv")
final.head()
final.dtypes
import plotly.express as px
import numpy as np

typed = "In-sample"
fig = px.treemap(final, path=["Data","Acronym"], values=typed)

fig.show()

output:

[Blank]

1 Answers

You are trying to plot too many items in the treemap.

  • I've effectively reduced it to rows that are in top 50th quantile. Very small items are arguably not relevant to this plot.
  • additionally just filtering to values >= 0 resolves

>=0 rows

fig = px.treemap(
    final.loc[final[typed].ge(0)],
    path=["Data", "Acronym"],
    values=typed,
)

quantile approach

import pandas as pd

final = pd.read_csv(
    "https://raw.githubusercontent.com/firmai/random-assets-two/master/test/file.csv"
)
final.head()
final.dtypes
import plotly.express as px
import numpy as np

typed = "In-sample"
fig = px.treemap(
    final.loc[pd.qcut(final[typed], q=4, labels=[0, 1, 2, 3]).ge(2)],
    path=["Data", "Acronym"],
    values=typed,
)

fig

enter image description here

Related