skojaku / core-periphery-detection

Python package for detecting core-periphery structure in networks.
Apache License 2.0
47 stars 5 forks source link

The Draw command doesn't work. #13

Closed JulienOx closed 3 years ago

JulienOx commented 3 years ago

So I managed to install cpnet. I then tried to run the example 1 to see if everything worked.

Everything does work until you try do draw the network using cpnet.draw().

TypeError Traceback (most recent call last)

in 6 fig = plt.figure(figsize=(8, 6)) 7 ax = plt.gca() ----> 8 ax, pos = cpnet.draw(G, c, x, ax) ~\miniconda3\lib\site-packages\cpnet\utils.py in draw(G, c, x, ax, draw_edge, font_size, pos, cmap, max_colored_group_num, draw_nodes_kwd, draw_edges_kwd, draw_labels_kwd, layout_kwd) 184 185 # Draw --> 186 nodes = nx.draw_networkx_nodes( 187 G, 188 pos, TypeError: draw_networkx_nodes() got an unexpected keyword argument 'zorder'. I looked at the source code, and you use this argument, "zorder = 3" , then 2, then 1. But looking at the networkx documentation for the draw_networkx_nodes(), I don't see what this argument is supposed to do. I am using Networkx 2.5 and python 3.8.5. Thanks for all the work, it is a very useful resource !
skojaku commented 3 years ago

Hi @JulienOx. Thanks for raising the issue in detail!. I will investigate and get back to you asap

JulienOx commented 3 years ago

Hello,

A quick fix was to remove the "zorder = 3" and the other two lines from the source code. Then everything works fine, but I seem to get slightly different results. I.E, in Example 1, for the Multiple core-periphery pairs, my graph is a bit different temp cpnet One of the green node is considered a core, where it is a periphery in the example. I doubt its related to this change with the zorders, but I still get the result after running the algo a couple of times. I don't think this is really relevant, as I don't really know what zorder does, even after looking at the source code for the networkx draw function.

skojaku commented 3 years ago

This is due to the stochasticity of the algorithm, meaning it provides you different results in different runs. So I think the difference is not due to the changes you made.

If you want to ensure the results to be the same, you can set the seed for random number generated (like numpy.random.seed) or increase the number of runs by passing "num_runs" parameter by KM_config(num_runs = 50) (num_runs=10 is the default)

skojaku commented 3 years ago

I believe the bug is now fixed. Please upgrade the package (the version is changed from 0.0.17 to 0.0.18). Also, feel free to let us know if you still see the bug!

JulienOx commented 3 years ago

Thank you !

Not sure if this is related, but the examples don't seem to open on github anymore ?

skojaku commented 3 years ago

From my side, I can see the notebook. Can you describe the issue in more detail?

JulienOx commented 3 years ago

all fixed now, not sure why it did that

skojaku commented 3 years ago

Great!