springer-math / Mathematics-of-Epidemics-on-Networks

Source code accompanying 'Mathematics of Epidemics on Networks' by Kiss, Miller, and Simon http://www.springer.com/us/book/9783319508047 . Documentation for the software package is at https://epidemicsonnetworks.readthedocs.io/en/latest/
MIT License
151 stars 61 forks source link

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

Open Ru-Zheng opened 2 years ago

Ru-Zheng commented 2 years ago

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._displaygraph(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 _displaygraph 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.

joelmiller commented 2 years ago

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.

Ru-Zheng commented 2 years ago

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.

joelmiller commented 2 years ago

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.