Fix: plot_network bug due to changed networkx draw function behavior #417
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
A change to the behavior the networkx function
draw_networkx_edges
disrupted the colorbar code in wntr'splot_network
function due to a mismatch in return object.The following code in
draw_networkx_edges
occurs in version 3.1 (probably 3.2 as well):however this changes to the following in version 3.3:
The graph we use in
plot_network
is a multigraph, souse_linecollection
now gets set to False, counter the the previous behavior. When this variable is false, the networkx function returns a list of FancyArrowPatches objects rather than a LineCollection object, which broke the way we handled colorbars. Additionally, it seems to change the plotting behavior so that the lines do not properly connect to nodes.In this PR,
arrows
is set to equal the argumentdirected
to achieve the original behavior. The old colormap code would be fixed as well with this change, but it depended on the output type fromdraw_networkx_edges
so I opted for an approach that doesn't have this dependency.Tests and documentation
I verified that the plots now look like they do when using networkx 3.1. I also added an extra figure to
test_plot_network2
to cover the case whendirected=True
.Acknowledgement
By contributing to this software project, I acknowledge that I have reviewed the software quality assurance guidelines and that my contributions are submitted under the Revised BSD License.