1 回答

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊
通過(guò)調(diào)整 customwrap 函數(shù)中的寬度,我能夠做出漂亮的旭日紋。答案由 plotly 的 GitHub 社區(qū)提供。
import plotly.express as px
import pandas as pd
import textwrap
def customwrap(s,width=30):
return "<br>".join(textwrap.wrap(s,width=width))
df = pd.read_excel("/Users/stuff/Desktop/test.xlsx")
g1 = df.Group1.map(customwrap)
g2 = df.Group2.map(customwrap)
g3 = df.Group3.map(customwrap)
g4 = df.Group4.map(customwrap)
my_values = df.Values
df = pd.DataFrame(
dict(group1=g1, group2=g2, group3=g3, group4=g4, my_values=my_values)
)
fig = px.sunburst(df, path=['group1', 'group2', 'group3', 'group4'], values='my_values')
fig.show()
添加回答
舉報(bào)