TypeError: plot() missing 1 required positional argument: 'kind'
TypeError: plot() missing 1 required positional argument: 'kind'
我正在使用 plotly 在网络图形上处理 Kaggle tutorial。经过一些更新以获得与 chart_studio 兼容的代码后,我现在收到错误:
TypeError: plot() missing 1 required positional argument: 'kind'
我为尝试获取图表而输入的代码是:
import plotly.express as px
import pandas as pd
import networkx as nx
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
import plotly.graph_objs as go
import numpy as np
init_notebook_mode(connected=True)
#AT&T network data
network_df=pd.read_csv('network_data.csv')
#source_ip and destination_ip are of our interest here. so we isolate them. We then get the unique ip addresses for getting
#the total number of nodes. We do this by taking unique values in both columns and joining them together.
A = list(network_df["source_ip"].unique())
B = list(network_df["destination_ip"].unique())
node_list = set(A+B)
#Creating the Graph
G = nx.Graph()
#Graph api to create an empty graph. And the below cells we will create nodes and edges and add them to our graph
for i in node_list:
G.add_node(i)
G.nodes()
pos = nx.spring_layout(G, k=0.5, iterations=50)
for n, p in pos.items():
G.nodes[n]['pos'] = p
edge_trace = go.Scatter(
x=[],
y=[],
line=dict(width=0.5,color='#888'),
hoverinfo='none',
mode='lines')
for edge in G.edges():
x0, y0 = G.node[edge[0]]['pos']
x1, y1 = G.node[edge[1]]['pos']
edge_trace['x'] += tuple([x0, x1, None])
edge_trace['y'] += tuple([y0, y1, None])
node_trace = go.Scatter(
x=[],
y=[],
text=[],
mode='markers',
hoverinfo='text',
marker=dict(
showscale=True,
colorscale='RdBu',
reversescale=True,
color=[],
size=15,
colorbar=dict(
thickness=10,
title='Node Connections',
xanchor='left',
titleside='right'
),
line=dict(width=0)))
for node in G.nodes():
x, y = G.nodes[node]['pos']
node_trace['x'] += tuple([x])
node_trace['y'] += tuple([y])
for node, adjacencies in enumerate(G.adjacency()):
node_trace['marker']['color']+=tuple([len(adjacencies[1])])
node_info = adjacencies[0] +' # of connections: '+str(len(adjacencies[1]))
node_trace['text']+=tuple([node_info])
#Start plotting
fig = go.Figure(data=[edge_trace, node_trace],
layout=go.Layout(
title='<br>AT&T network connections',
titlefont=dict(size=16),
showlegend=False,
hovermode='closest',
margin=dict(b=20,l=5,r=5,t=40),
annotations=[ dict(
text="No. of connections",
showarrow=False,
xref="paper", yref="paper") ],
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)))
#the above code gave me an error because it wasn't set up for chart_studio
iplot(fig)
plotly.plot(fig)
from chart_studio.plotly import plot
from chart_studio import plotly
import plotly
import chart_studio
chart_studio.tools.set_credentials_file(username='anand0427', api_key='5Xd8TlYYqnpPY5pkdGll')
iplot(fig,"anand0427",filename="Network Graph.html")
iplot(fig)
plotly.plot(fig)
如有任何帮助,我们将不胜感激。
我环顾四周,试图找出 kind 的含义以及如何针对此图表调整它。
完整追溯:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-40-e49e5cb9a1e3> in <module>()
2
3 iplot(fig)
----> 4 plotly.plot(fig)
TypeError: plot() missing 1 required positional argument: 'kind'
问题出在您的代码和教程中使用的不明确的导入语句。
你有
from chart_studio import plotly
import plotly
表示定义了两次plotly
,只剩下第二次定义。教程也有同样的问题,from plotly import plotly
后跟[=13=].
所以当你调用 plotly.plot()
时,你并不是在调用 chart_studio.plotly.plot()
,我相信这是你的意图,而是你调用了 plot()
中定义的函数17=],其in-code documentation表示不打算直接调用。
除非您知道自己需要它,否则请删除行 import plotly
,或将这两行导入行之一更改为 as <some other name>
,这样您就可以引用 chart_studio.plotly
和以不同的、明确的名称为基础 plotly
。
我正在使用 plotly 在网络图形上处理 Kaggle tutorial。经过一些更新以获得与 chart_studio 兼容的代码后,我现在收到错误:
TypeError: plot() missing 1 required positional argument: 'kind'
我为尝试获取图表而输入的代码是:
import plotly.express as px
import pandas as pd
import networkx as nx
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
import plotly.graph_objs as go
import numpy as np
init_notebook_mode(connected=True)
#AT&T network data
network_df=pd.read_csv('network_data.csv')
#source_ip and destination_ip are of our interest here. so we isolate them. We then get the unique ip addresses for getting
#the total number of nodes. We do this by taking unique values in both columns and joining them together.
A = list(network_df["source_ip"].unique())
B = list(network_df["destination_ip"].unique())
node_list = set(A+B)
#Creating the Graph
G = nx.Graph()
#Graph api to create an empty graph. And the below cells we will create nodes and edges and add them to our graph
for i in node_list:
G.add_node(i)
G.nodes()
pos = nx.spring_layout(G, k=0.5, iterations=50)
for n, p in pos.items():
G.nodes[n]['pos'] = p
edge_trace = go.Scatter(
x=[],
y=[],
line=dict(width=0.5,color='#888'),
hoverinfo='none',
mode='lines')
for edge in G.edges():
x0, y0 = G.node[edge[0]]['pos']
x1, y1 = G.node[edge[1]]['pos']
edge_trace['x'] += tuple([x0, x1, None])
edge_trace['y'] += tuple([y0, y1, None])
node_trace = go.Scatter(
x=[],
y=[],
text=[],
mode='markers',
hoverinfo='text',
marker=dict(
showscale=True,
colorscale='RdBu',
reversescale=True,
color=[],
size=15,
colorbar=dict(
thickness=10,
title='Node Connections',
xanchor='left',
titleside='right'
),
line=dict(width=0)))
for node in G.nodes():
x, y = G.nodes[node]['pos']
node_trace['x'] += tuple([x])
node_trace['y'] += tuple([y])
for node, adjacencies in enumerate(G.adjacency()):
node_trace['marker']['color']+=tuple([len(adjacencies[1])])
node_info = adjacencies[0] +' # of connections: '+str(len(adjacencies[1]))
node_trace['text']+=tuple([node_info])
#Start plotting
fig = go.Figure(data=[edge_trace, node_trace],
layout=go.Layout(
title='<br>AT&T network connections',
titlefont=dict(size=16),
showlegend=False,
hovermode='closest',
margin=dict(b=20,l=5,r=5,t=40),
annotations=[ dict(
text="No. of connections",
showarrow=False,
xref="paper", yref="paper") ],
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)))
#the above code gave me an error because it wasn't set up for chart_studio
iplot(fig)
plotly.plot(fig)
from chart_studio.plotly import plot
from chart_studio import plotly
import plotly
import chart_studio
chart_studio.tools.set_credentials_file(username='anand0427', api_key='5Xd8TlYYqnpPY5pkdGll')
iplot(fig,"anand0427",filename="Network Graph.html")
iplot(fig)
plotly.plot(fig)
如有任何帮助,我们将不胜感激。
我环顾四周,试图找出 kind 的含义以及如何针对此图表调整它。
完整追溯:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-40-e49e5cb9a1e3> in <module>()
2
3 iplot(fig)
----> 4 plotly.plot(fig)
TypeError: plot() missing 1 required positional argument: 'kind'
问题出在您的代码和教程中使用的不明确的导入语句。
你有
from chart_studio import plotly
import plotly
表示定义了两次plotly
,只剩下第二次定义。教程也有同样的问题,from plotly import plotly
后跟[=13=].
所以当你调用 plotly.plot()
时,你并不是在调用 chart_studio.plotly.plot()
,我相信这是你的意图,而是你调用了 plot()
中定义的函数17=],其in-code documentation表示不打算直接调用。
除非您知道自己需要它,否则请删除行 import plotly
,或将这两行导入行之一更改为 as <some other name>
,这样您就可以引用 chart_studio.plotly
和以不同的、明确的名称为基础 plotly
。