Sorry for the strange title. Didn’t know how to word it.
Here’s my (working) code:
import pandas as pd
import plotly.graph_objects as go
def make_list():
# [label, parent, value, color]
data = [['Things', '', '', ''],
['Solid', 'Things', '', ''],
[f'Wood', 'Solid', 100, "0, 0, 0"],
[f'Stone', 'Solid', 100, "0, 0, 0"],
[f'Glass', 'Solid', 100, "0, 0, 0"],
[f'Steel', 'Solid', 100, "0, 0, 0"],
[f'Plastic', 'Solid', 100, "0, 0, 0"],
[f'Gold', 'Solid', 100, "0, 0, 0"],
[f'Silver', 'Solid', 100, "0, 0, 0"],
[f'Plastic', 'Solid', 100, "0, 0, 0"],
['Gas', 'Things', '', ''],
['Liquid', '', '', ''],
['Plasma', '', '', ''],
['Something', '', '', ''],
['Something1', '', '', ''],
['Something2', '', '', '']]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns=['id', 'parent', 'value', 'color'])
return df
df = make_list()
print(df)
fig = go.Figure(go.Treemap(labels=df['id'], parents=df['parent'], values=df['value'], branchvalues='total', textinfo='label', name=''))
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
fig.write_image("fig1.svg")
Now, this generates the solids just fine (
but when I add the gases:
import pandas as pd
import plotly.graph_objects as go
def make_list():
# [label, parent, value, color]
data = [['Things', '', '', ''],
['Solid', 'Things', '', ''],
[f'Wood', 'Solid', 100, "0, 0, 0"],
[f'Stone', 'Solid', 100, "0, 0, 0"],
[f'Glass', 'Solid', 100, "0, 0, 0"],
[f'Steel', 'Solid', 100, "0, 0, 0"],
[f'Plastic', 'Solid', 100, "0, 0, 0"],
[f'Gold', 'Solid', 100, "0, 0, 0"],
[f'Silver', 'Solid', 100, "0, 0, 0"],
[f'Plastic', 'Solid', 100, "0, 0, 0"],
['Gas', 'Things', '', ''],
[f'Air', 'Gas', 100, "0, 0, 0"],
[f'Steam', 'Gas', 100, "0, 0, 0"],
[f'Fart', 'Gas', 100, "0, 0, 0"],
[f'Nitrogen', 'Gas', 100, "0, 0, 0"],
[f'Oxygen', 'Gas', 100, "0, 0, 0"],
[f'Neon', 'Gas', 100, "0, 0, 0"],
[f'Helium', 'Gas', 100, "0, 0, 0"],
[f'Carbon Dioxide', 'Gas', 100, "0, 0, 0"],
[f'Carbon Monoxide', 'Gas', 100, "0, 0, 0"],
[f'Natural Gas', 'Gas', 100, "0, 0, 0"],
['Liquid', '', '', ''],
['Plasma', '', '', ''],
['Something', '', '', ''],
['Something1', '', '', ''],
['Something2', '', '', '']]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns=['id', 'parent', 'value', 'color'])
return df
df = make_list()
print(df)
fig = go.Figure(go.Treemap(labels=df['id'], parents=df['parent'], values=df['value'], branchvalues='total', textinfo='label', name=''))
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
fig.write_image("fig1.svg")
Then I just get a blank, white picture. (
)What did I do wrong? I checked for “invisible characters” but I could not find any, I copy-pasted the names over so I didn’t make a typo. Is there a limitation that I’m not aware about?