最终我得到了如下代码,并且可以正常运行,没有出现任何错误:
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, how='any'),
target = df['Target'].dropna(axis=0, how='any'),
value = df['Value'].dropna(axis=0, how='any'),
)
)
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(fig, filename='Test')
只显示了一个大的空白区域:
![enter image description here](https://istack.dev59.com/AQz6L.webp)
![enter image description here](https://istack.dev59.com/OvLxk.webp)
编辑:我也在Plotly论坛上发布了这个问题:https://community.plot.ly/t/no-output-from-plotly-offline-iplot/8086 -
jupyter notebook --NotebookApp.iopub_data_rate_limit=1.0e10
。 - elz