gpt4 book ai didi

python - plotly.offline.iplot 在 Jupyter Notebook/Lab 中给出一个大的空白字段作为其输出

转载 作者:太空狗 更新时间:2023-10-29 17:28:32 24 4
gpt4 key购买 nike

我正在尝试在 Jupyter notebook 中创建一个 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, 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运行一次笔记本中的所有单元格后,终端看起来像这样: enter image description here

谁能指出我哪里出错了?

最佳答案

我过去在 Jupyter 中遇到过类似的脱机绘图问题 - 有时绘图无法显示的时间/原因有时出人意料地不一致。从提高数据速率限制开始可能值得一试。

jupyter 笔记本 --NotebookApp.iopub_data_rate_limit=1.0e10

关于python - plotly.offline.iplot 在 Jupyter Notebook/Lab 中给出一个大的空白字段作为其输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48560138/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com