0

I plan to use EditableGraph of Netgraph as the foundation of my application. However, I have encountered the following issue. Let us consider the following program that draws a small graph.

import matplotlib.pyplot as plt
from netgraph import EditableGraph
from numpy import array
fig,ax = plt.subplots()
editgraph = EditableGraph([(0,1),(0,2),(2,2)],
 node_label_fontdict=dict(size=9),
 node_labels=True,
 edge_width=2,
 node_layout= {0: array([0.5, 0.5]), 1: array([0.25, 0.5]), 2: array([0.75, 0.5])},
 ax=ax)
plt.show()

If:

  1. I create a self loop on node 1 (i.e. edge (1,1) );
  2. I add a label on this loop;
  3. The label cannot be added and I have the error message below:
Initiated writing label(s).
C:\Users\...\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\netgraph\_main.py:1082: UserWarning: Plotting of edge labels for self-loops not supported for straight edges.
Ignoring edge with label: 
 warnings.warn(msg)
Traceback (most recent call last):
 File "C:\Users\...\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\matplotlib\cbook.py", line 298, in process
 func(*args, **kwargs)
 File "C:\Users\...\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\netgraph\_interactive_variants.py", line 518, in _on_key_press
 self._edit_labels(event.key)
 File "C:\Users\...\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\netgraph\_interactive_variants.py", line 550, in _edit_labels
 self._edit_edge_label(artist, key)
 File "C:\Users\...\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\netgraph\_interactive_variants.py", line 571, in _edit_edge_label
 self._edit_text_object(self.edge_label_artists[edge], key)
 ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
KeyError: (1, 1)

The resulting graph is as follows:

Resulting graph However when:

  1. I first add a label to the self loop (2,2);
  2. Then I create the self-loop (1,1);
  3. I can label the self-loop (1,1) normally !?

Moreover, I have not encountered any problems with edges that are not self-loops.

What is the problem with this example that prevents adding a label to a new self-loop? Why does labeling the existing self-loop enable the possibility to label the created self-loop? How can this issue be fixed? It would be helpful to be able to label the self-loop using EditableGraph regardless of the protocol used.

asked Feb 14, 2024 at 21:03
4
  • That very much looks like a bug. I can't look into it right now, but I will do so early next week. If you could submit this issue to the Netgraph issue tracker, then I definitely won't forget. Commented Feb 15, 2024 at 14:52
  • Thanks ! This prevents to fully use it. I have submitted this isssue to Netgraph issue tracker. I have another question how can I resize EditableGraph to fully occupy the figure? Commented Feb 15, 2024 at 17:46
  • 1
    Try out these suggestions here. Commented Feb 15, 2024 at 18:52
  • 1
    This bug should now be resolved on the dev branch. Commented Feb 19, 2024 at 13:32

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.