我试图在Jupyter笔记本中创建一个Sankey图表,我的代码基于
the first example shown here.
我最终得到了这个,我可以运行而不会出现任何错误:
- import numpy as npy
- import pandas as pd
- import plotly as ply
- ply.offline.init_notebook_mode(connected=True)
- df = pd.read_csv('C:\\Users\\a245401\\Desktop\\Test.csv',sep=';')
- print(df.head())
- print(ply.__version__)
- data_trace = dict(
- type='sankey',domain = dict(
- x = [0,1],y = [0,1]
- ),orientation = "h",valueformat = ".0f",node = dict(
- pad = 10,thickness = 30,line = dict(
- color = "black",width = 0.5
- ),label = df['Node,Label'].dropna(axis=0,how='any'),color = df['Color']
- ),link = dict(
- source = df['Source'].dropna(axis=0,target = df['Target'].dropna(axis=0,value = df['Value'].dropna(axis=0,)
- )
- print(data_trace)
- layout = dict(
- title = "Test",height = 772,width = 950,font = dict(
- size = 10
- ),)
- print(layout)
- fig = dict(data=[data_trace],layout=layout)
- ply.offline.iplot(fig,filename='Test')
csv文件看起来像这样:
- Source;Target;Value;Color;Node,Label
- 0;2;2958.5;#262C46;Test 1
- 0;2;236.7;#262C46;Test 2
- 0;2;1033.4;#262C46;Test 3
- 0;2;58.8;#262C46;Test 4
- 0;2;5.2;#262C46;Test 5
- 0;2;9.4;#262C46;Test 6
- 0;2;3.4;#262C46;Test 7
它似乎运行良好,各种输出乍一看,但ply.offline.iplot的最终输出(图,文件名=’测试’)只显示一个大的空白字段:
在运行笔记本中的所有单元格后,终端看起来像这样:
有人可以指点我到哪里错了吗?
>编辑:我也在剧情论坛上发布了这个问题:https://community.plot.ly/t/no-output-from-plotly-offline-iplot/8086 –