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
Digraph Arrows to fix #2757 #2760
Conversation
Thanks, that is a good start. Can you figure out how to get the arrows to scale correctly with node size? For circular nodes this shouldn't be too complicated. For other shapes this will be harder since you probably want to find the closest polygon vertex and route the arrow there.
|
That looks good. I agree the general marker case is a little tricky. One thing that I would expect users to want to do is to adjust the arrow sizes. At minimum maybe setting the mutation_scale? |
Also see #2163 for arrow colors fixes |
And #1199 for alpha-values setting |
Two keyword arguments to define the style and size of the arrow are included ( The arrows will never overlap the marker, however for some markers (namely the square, diamond and triangles) the arrow might be clearly distanced for the marker. However, this doesn't seem to affect (too much) the quality of the drawings. For the rest of the markers, which it works well (polygons with more than 4 sides). |
I've been wondering about what should be returned with Another approach would be to make two functions -- one for edges and one for arrows. |
@dschult We could try to use a Making a second function is a good idea too depending on the number of flexibility in terms |
I think for now let's try to get the features in with one function and a few arrow-specific arguments. I guess I didn't understand that for the arrows case we don't have a line collection at all... Guess I need to look at the code more. :} It seems like |
Yes actually a line collection is returned when the graph is either non-directed or the arrows are disabled. For the case when the graph is directed and arrows are enabled we could use a patch collection for the arrows. The thing is that Probably the best idea is to leave a couple of arrow-specific arguments dealing with the head of the arrow and try to keep The remaining question is what to return when using arrows. |
I'm fine with returning None for the time being. |
Maybe a list of |
Yes -- that is a good idea. |
This is a really great contribution. |
I'm glad to be of some help to such an amazing package, keep the good work. Should I include a plot example in :examples:drawing: varying for instance alpha values, or just include it in the documentation of |
I think the examples folder would be for something bigger while the doc_string works better for a small example. If you can create a 2-3 edge network with different alphas for each arrow, I'm guessing that would be short enough to put in the doc_string. I'd prefer it there. Then as a separate PR we could create an example for the examples folder that highlights the arrows features more generally. Does this make sense? Is there a better way? |
Yes -- it makes sense. I can eventually make a pull request to add a plot with the arrows in the example directory. I added an example to change the alpha values in the doc-string. I also added a list in the returns section of the doc-string, it is not clear to me what is the proper syntax used when two different types are returned depending on the use of arrows or not. So I might need to change it, I currently added:
Should I change it? |
This pull request targets to replace the thicker lines used to draw arcs (directed edges) used in the nx_pylab.py file with arrow heads.
The main idea is to replace the
matplotlib.collections.LineCollection
with a list ofmatplotlib.patches.FancyArrowPatch
.The implementation is a bit slower than the original, but adds some clarity when zooming on a a network, e.g. consider the following the network with N nodes and N*2 edges:
For N=100, this normally draws:
With this pull request:
For N=1000
Zooming on the network gives:
With this pull request:
I added the keyword
arrowstyle
to be able to use all the styles formatplotlib.patches.FancyArrowPatch
, however, the drawing is chaotic for some of them.