从documentation的这一部分,我期望以下代码生成一个条形图,其中每个条形图都包含与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)
1条答案
按热度按时间igsr9ssn1#
您可以尝试将texttemplate改为text,如下所示: