paulbrodersen / netgraph

Publication-quality network visualisations in python
GNU General Public License v3.0
659 stars 38 forks source link

Edges not curved #90

Open BankNatchapol opened 1 month ago

BankNatchapol commented 1 month ago

From this example: https://netgraph.readthedocs.io/en/latest/sphinx_gallery_output/plot_06_labels.html#sphx-glr-sphinx-gallery-output-plot-06-labels-py the graph should looks like this image but, it's this instead image

paulbrodersen commented 1 month ago

Hi, thanks for raising the issue.

  1. Have you changed the value of k? This parameter determines the straightness of the edges.
g = Graph(triangle, edge_layout='curved', edge_layout_kwargs=dict(k=0.025))
  1. Does the issue persist on the dev branch?

You can install the dev branch via pip:

pip install https://github.com/paulbrodersen/netgraph/archive/dev.zip
BankNatchapol commented 1 month ago

@paulbrodersen Thank you for your answer. i haved tried install with pip install https://github.com/paulbrodersen/netgraph/archive/dev.zip (nothing change) and also tried removing edge_layout_kwargs=dict(k=0.025) This is the result image

which is still not completely correct, there should be 2 edges a->c and c->a

code:

import numpy as np
import matplotlib.pyplot as plt
import networkx as nx

from netgraph import Graph

fig, (ax1, ax2) = plt.subplots(1, 2)

triangle = [(0, 1), (0, 2), (1, 1), (1, 2), (2, 0)]

node_positions = {
    0 : np.array([0.2, 0.2]),
    1 : np.array([0.5, 0.8]),
    2 : np.array([0.8, 0.2]),
}

g = Graph(
    triangle,
    node_layout=node_positions, edge_layout='curved',
    node_labels={0 : 'a', 1 : 'b', 2 : 'c'},
    edge_labels=True, edge_label_fontdict=dict(fontweight='bold'),
    ax=ax1,
)

h = Graph(nx.complete_graph(7), edge_width=0.5, node_labels=True,
      node_label_fontdict=dict(size=14), node_label_offset=0.075, ax=ax2)
paulbrodersen commented 1 month ago

The edge layout key-word argument bundle_parallel_edges used to be False by default but is now True (no idea how that happened). You can restore the original behaviour by setting it to False explicitly:

g = Graph(
    triangle,
    node_layout=node_positions, edge_layout='curved', edge_layout_kwargs=dict(bundle_parallel_edges=False), 
    node_labels={0 : 'a', 1 : 'b', 2 : 'c'},
    edge_labels=True, edge_label_fontdict=dict(fontweight='bold'),
    ax=ax1,
)