Reputation: 47
I am working through a Kaggle tutorial on a network graphic with plotly. After some updating to get the code compatible with chart_studio, I am now getting the error:
TypeError: plot() missing 1 required positional argument: 'kind'
The code I have entered to try and get the graph is:
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)
Any help would be appreciated.
I have looked around trying to figure out what kind means and how to adapt it for this graph.
Full traceback:
---------------------------------------------------------------------------
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'
Upvotes: 1
Views: 4132
Reputation: 21
TypeError: plot() is missing one required positional argument: 'kind' If this error happens, check weather plotly.offline is imported (if you are imported plotly only)
Upvotes: 1
Reputation: 12229
The problem comes from the ambiguous import statements that both your code and the tutorial use.
You have
from chart_studio import plotly
import plotly
which means that you define plotly
twice, and only the second definition remains. The tutorial has the same problem, with from plotly import plotly
followed by import plotly
.
So when you call plotly.plot()
, you're not calling chart_studio.plotly.plot()
, which I believe is your intention, but instead you're calling the plot()
function defined in plotly/__init__.py
, whose in-code documentation says it's not intended to be called directly.
Unless you know you need it, remove the line import plotly
, or change one of those two import lines to say as <some other name>
, which will let you refer to chart_studio.plotly
and the base plotly
by different, unambiguous names.
Upvotes: 2