Mathematics-of-Epidemics-on-Networks icon indicating copy to clipboard operation
Mathematics-of-Epidemics-on-Networks copied to clipboard

TypeError: draw_networkx_edges() got an unexpected keyword argument 'with_labels'

Open Ru-Zheng opened this issue 2 years ago • 3 comments

my codes: import networkx as nx import EoN import matplotlib.pyplot as plt

G = nx.watts_strogatz_graph(100, 5, 0.9) nx_kwargs = {"with_labels": True}

sim = EoN.Gillespie_SIR(G, 1, 0.1, return_full_data=True)

t = 0.0 while t < 40: sim.display(time=t, **nx_kwargs) plt.show() t += 0.5

tree = sim.transmission_tree() hierarchy_tree = EoN.hierarchy_pos(tree) nx.draw(tree, hierarchy_tree, with_labels=True) plt.show()


However,I meet some problem:

Traceback (most recent call last): File "D:\python_project\sir.py", line 15, in sim.display(time=t, **nx_kwargs) File "D:\python3.9.10\lib\site-packages\EoN\simulation_investigation.py", line 875, in display self.display_graph(pos, nodestatus, nodelist, status_order, statuses_to_plot, graph_ax, **nx_kwargs) File "D:\python3.9.10\lib\site-packages\EoN\simulation_investigation.py", line 639, in display_graph nx.draw_networkx_edges(self.G, pos, edgelist=edgelist, ax=ax, **nx_kwargs) TypeError: draw_networkx_edges() got an unexpected keyword argument 'with_labels'

Can you help me to solve this problem,thank you.

Ru-Zheng avatar Aug 23 '22 07:08 Ru-Zheng

Hi,

Can you give me information about what version of networkx you're running?

This is odd because that code runs okay for me. The error is suggesting that when EoN calls draw_networkx_edges, it is sending an argument that the networkx method isn't expecting.

joelmiller avatar Aug 23 '22 08:08 joelmiller

Hi, My networkx version is 2.8.2,when I rewrite simulation_investigation.py line 639:nx.draw_networkx_edges(self.G, pos, edgelist=edgelist, ax=ax, **nx_kwargs) to nx.draw_networkx(self.G, pos, edgelist=edgelist, ax=ax, **nx_kwargs), it is worked.

Ru-Zheng avatar Aug 23 '22 08:08 Ru-Zheng

You may want to add nodelist = [] to the edited function call. This was obviously supposed to only draw the edges (with the nodes handled separately), but the version you're calling will also draw all the nodes in this call. I think adding nodelist=[] will prevent that.

joelmiller avatar Aug 23 '22 10:08 joelmiller