pnnl / HyperNetX

Python package for hypergraph analysis and visualization.
https://hypernetx.readthedocs.io
Other
561 stars 92 forks source link

Overlapping of nodes in the draw diagram #123

Closed Ramshell closed 10 months ago

Ramshell commented 1 year ago

Describe the bug The draw function overlaps edges, making it seem that they share nodes.

To Reproduce Steps to reproduce the behavior:

  1. Run the following code
    
    import matplotlib.pyplot as plt
    import hypernetx as hnx
    articles = {
        'CA': ('1', '3', '5', '6', '13', '80', '92', '8', '24', '36', '63', '75', '86', '88', '91',
                '10', '33', '57', '84', '27', '50', '67', '18', '60', '69', '81', '23', '31', '45', '87',
                '4', '71', '16', '17', '30', '55', '62', '93', '2', '19', '48', '7', '14', '15', '44', '58'),
        'MRDM': ('1', '3', '5', '6', '13', '27', '38', '42', '67', '80',
                 '92', '9', '23', '29', '31', '34', '35', '45', '87', '88',
                 '33', '84', '18', '74', '98', '21', '82', '11', '19', '48',
                 '53', '61', '73', '85', '96', '97', '99', '7', '44', '95', '40', '76'),
        'DA': ('16', '17', '30', '62', '93', '50', '14', '15', '39', '40', '41', '76'),
        'Graphs': ('9', '23', '29', '31', '34', '35', '45', '87',), 
        'Onto': ('1', '3', '5', '6', '13', '27', '38', '42', '67', '80', '92', '50',), 
    }
    H = hnx.Hypergraph(articles)
    kwargs = {
        'with_node_labels': True,
        'with_node_counts': False,
        'with_edge_counts': False,
    }

hnx.drawing.draw( H_collapsed, edges_kwargs={ 'linewidths': 2, }, nodes_kwargs={ 'facecolors': colors }, edge_labels_kwargs={ 'fontsize': 16, }, **kwargs) plt.show()


2. See the result:
![image](https://github.com/pnnl/HyperNetX/assets/12850723/71e78658-56e5-485b-8695-af77dd95d180)
As an example, the node 76 seems to be *inside* the edge Onto, but it's actually not.

**Expected behavior**
Edges should have node inside them only when they're actually part of them.

**Environment (please complete the following information):**
 - OS: Linux
 - Python Version Py3.9
brendapraggastis commented 1 year ago

@Ramshell The draw function often has overlapping or planarity issues when there are a large number of nodes. There are a couple of things you can do.

  1. Change the layout. Any networkx layout may be used.
  2. Set return_pos=True, then tweek the returned dictionary of node positions until things line up the way you want.
  3. Collapse the nodes and return the equivalence classes. This would be my choice. image Equivalence classes in a dictionary: {'10: 17': ['10', '2', '24', '36', '4', '55', '57', '58', '60', '63', '69', '71', '75', '8', '81', '86', '91'], '11: 13': ['11', '21', '53', '61', '73', '74', '82', '85', '95', '96', '97', '98', '99'], '1: 9': ['1', '13', '27', '3', '5', '6', '67', '80', '92'], '14: 7': ['14', '15', '16', '17', '30', '62', '93'], '18: 8': ['18', '19', '33', '44', '48', '7', '84', '88'], '29: 4': ['29', '34', '35', '9'], '23: 4': ['23', '31', '45', '87'], '38: 2': ['38', '42'], '39: 2': ['39', '41'], '40: 2': ['40', '76'], '50: 1': ['50']} You can rename the node labels to use representatives you wish to emphasize as well.