使用 python 和 plotly,无法将字符串数组传递给文本参数
using python and plotly, can't pass string array to text parameter
(我显然是编程和 python 的新手。)
我想在使用 python 和 plotly 创建的堆叠条形图中添加一些文本。如果我直接提供文本参数,一切正常。如果我将文本参数设置为列表,文本参数将被忽略。
以下效果很好,第一个小节放置 "A",第二个小节放置 "B",第三个小节放置 "C"。
this_bar = go.Bar(
x = list_of_people,
y = y_axis,
text = ["A", "B", "C"],
name = 'Bar Chart'
)
以下代码的工作方式不同,我不确定为什么。它完全忽略文本参数(并且不放置任何带有任何条的文本):
alphabet = ["A", "B", "C"]
this_bar = go.Bar(
x = list_of_people,
y = y_axis,
text = [alphabet],
name = 'Bar Chart'
)
Plotly 的文档似乎表明我应该能够做到这一点,但我一定是遗漏了一些简单的东西。
text (string)
default: ""
Sets text elements associated with each (x,y) pair. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (x,y) coordinates.(https://plot.ly/python/reference/#bar-text)
如果需要的话,我正在使用 Python 3.4。
你需要
text = alphabet
当你
alphabet = ["A", "B", "C"]
text = [ alphabet ]
然后你得到二维列表(列表中的列表)
text = [ ["A", "B", "C"] ]
(我显然是编程和 python 的新手。) 我想在使用 python 和 plotly 创建的堆叠条形图中添加一些文本。如果我直接提供文本参数,一切正常。如果我将文本参数设置为列表,文本参数将被忽略。
以下效果很好,第一个小节放置 "A",第二个小节放置 "B",第三个小节放置 "C"。
this_bar = go.Bar(
x = list_of_people,
y = y_axis,
text = ["A", "B", "C"],
name = 'Bar Chart'
)
以下代码的工作方式不同,我不确定为什么。它完全忽略文本参数(并且不放置任何带有任何条的文本):
alphabet = ["A", "B", "C"]
this_bar = go.Bar(
x = list_of_people,
y = y_axis,
text = [alphabet],
name = 'Bar Chart'
)
Plotly 的文档似乎表明我应该能够做到这一点,但我一定是遗漏了一些简单的东西。
text (string) default: "" Sets text elements associated with each (x,y) pair. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (x,y) coordinates.(https://plot.ly/python/reference/#bar-text)
如果需要的话,我正在使用 Python 3.4。
你需要
text = alphabet
当你
alphabet = ["A", "B", "C"]
text = [ alphabet ]
然后你得到二维列表(列表中的列表)
text = [ ["A", "B", "C"] ]