从文档的这一部分中,我期望以下代码生成一个条形图,其中每个条形都包含根据
df['label']
相应的文本。相反,每个条都包含在 df['Foo']
中找到的字符串。如何让 texttemplate
正常工作,即让每个栏都包含 df['label']
中的文本?
>>> import plotly
>>> import pandas as pd
>>> import plotly.graph_objects as go
>>> plotly.__version__
5.17.0
>>> df = pd.DataFrame(data={"Foo":['a','b','c'],'Bar':[2,5,10], 'label':['alpha','beta', 'charlie']})
df
Foo Bar label
0 a 2 alpha
1 b 5 beta
2 c 10 charlie
>>> bar = go.Bar(x=df['Foo'], y=df['Bar'], texttemplate ="%{label}")
>>> go.Figure(data=bar)