首页 > 解决方案 > 可以使用 Python 在 Plotly 中定义 X 和 Y 值吗?

问题描述

例如,我有以下

情景 1 -

x_names = ['John', 'Jill', 'Sandy']
y_ages = 8,11,10
Trace00 = dict(type = 'bar', x=[x_names], y= [y_ages])
plotly.offline.iplot([Trace00])

结果:由于某种原因,图表未显示任何值

方案 2

Trace00= dict(type= 'bar', x= ['jack', 'jill', 'sandy'], y= [ 8,11,10])
plotly.offline.iplot([Trace00])

结果:成功绘制详细信息。

问题:我可以在轨迹中定义我的 x 值和 y 值吗?无需输入每个对应的值?

标签: pythonpython-3.xplotly-python

解决方案


试试这个,它会工作的。当您将列表列表传递给 x 和 y 时,您将得到失败的输出。

x_names = ['John', 'Jill', 'Sandy']

y_ages = 8,11,10

Trace00 = dict(type = 'bar', x=x_names, y= y_ages)

plotly.offline.iplot([Trace00])

推荐阅读