-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error Attempting to Iterate Over LineCollection #3337
Comments
The example code you point to doesn't have a list that iterates over the edges.
Try the code at this documentation link |
Thanks for the reply. I have tried this way just now and it does not work either. This might be an issue with a loss of functionality in a new version of matplotlib, what version of matplotlib are you using? I am on 3.0.2, which apparently does not support indexing on LineCollection objects. |
Hmmm... I think 3.0.2 does allow indexing on LineCollection. I have used it with 3.0.3 so I know it works there, and it worked with 2.x. This is an example session. Figure shows up fine -- no errors.
|
Hello everyone :) In the matplotlib documentation about Collections API they state (somehow, it's not very clear) that the Collections act as a whole. I've talked with the developers of matplotlib and they explained me that it's a design choice not to let the users iterate this monolithic structure. So it's not a bug. As to the alpha channels of the edges, there's a trick. Not very elegant but, at least, relies fully on the public API and without any bad workaround. It works by setting the alpha values in the RGBA notation. edges = nx.draw_networkx_edges(G, ... )
edges.set_alpha(None) # needed up to Networkx 3.6
edges.set_color( RGBAList ) Where I hope it can help others in future :) |
I don't think that Matplotlib's Collection object have ever been iterable. Internally we do a fair amount of implicit broadcasting / zipping / colormapping that would be very difficult to keep in sync if we also let users reach in and touch individual elements (the number of notional elements is not ever really fixed if you set the offsets). It looks like in nx21 (via #2760) nx changed to sometimes returning a Not sure what the best path out of this is though. |
draw_networkx_edges used touse a LineCollection (presumably for performance reasons) when drawing un-directed graphs and generate many FancyArrowPatch objects when drawing directed graphs. This resulted in issues due to return type instability (networkx#3337) and inconsistency with handling the input (networkx#3398). closes networkx#3398 closes networkx#3337
…4360) * API: always use list of FancyArrowPatch rather than LineCollection draw_networkx_edges used touse a LineCollection (presumably for performance reasons) when drawing un-directed graphs and generate many FancyArrowPatch objects when drawing directed graphs. This resulted in issues due to return type instability (#3337) and inconsistency with handling the input (#3398). closes #3398 closes #3337 * DOC: add link to PR * MNT: clean out remaining LineCollection usage * ENH: add a first attempt at drawing a self-loop It works, but still needs some thought on deciding how big to draw the self-loop. * Change tests for LineCollection replacement with list of FancyArrows Co-authored-by: Dan Schult <dschult@colgate.edu>
…etworkx#4360) * API: always use list of FancyArrowPatch rather than LineCollection draw_networkx_edges used touse a LineCollection (presumably for performance reasons) when drawing un-directed graphs and generate many FancyArrowPatch objects when drawing directed graphs. This resulted in issues due to return type instability (networkx#3337) and inconsistency with handling the input (networkx#3398). closes networkx#3398 closes networkx#3337 * DOC: add link to PR * MNT: clean out remaining LineCollection usage * ENH: add a first attempt at drawing a self-loop It works, but still needs some thought on deciding how big to draw the self-loop. * Change tests for LineCollection replacement with list of FancyArrows Co-authored-by: Dan Schult <dschult@colgate.edu>
This is less a bug with the code base and more a bug in the examples, but as a result a number of pieces of example code do not work any longer.
I have cobbled together code that uses the Directed Graph (https://networkx.github.io/documentation/stable/auto_examples/drawing/plot_directed.html#) example code to implement color maps, line alphas, and a colorbar. Apparently matplotlib.collections.LineCollection objects are no longer iterable, and thus the code
does not work (nor does using something like
for e in edges:
orfor i in range(len(edges)):
The problem also arises in trying to create a colorbar legend by passing the
edges
object tompl.collections.PatchCollection()
as this too raise the error that LineCollection objects are not iterable.Versions:
Python - 3.6
Networkx - 2.2
Matplotlib - 3.0.2
Here is the full code (assuming you have a graph
G
already):The text was updated successfully, but these errors were encountered: