Skip to content

Commit b8a11e2

Browse files
committed
Bugfix for arcs
1 parent 4a6708d commit b8a11e2

10 files changed

Lines changed: 94 additions & 11 deletions

File tree

docs/source/sg_execution_times.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Computation times
88
=================
9-
**00:00.158** total execution time for 80 files **from all galleries**:
9+
**00:00.092** total execution time for 82 files **from all galleries**:
1010

1111
.. container::
1212

@@ -32,8 +32,11 @@ Computation times
3232
* - Example
3333
- Time
3434
- Mem (MB)
35-
* - :ref:`sphx_glr_gallery_style_plot_edge_geometries.py` (``../../gallery/style/plot_edge_geometries.py``)
36-
- 00:00.158
35+
* - :ref:`sphx_glr_gallery_other_plot_multiarc.py` (``../../gallery/other/plot_multiarc.py``)
36+
- 00:00.060
37+
- 0.0
38+
* - :ref:`sphx_glr_gallery_other_plot_filled_edges.py` (``../../gallery/other/plot_filled_edges.py``)
39+
- 00:00.032
3740
- 0.0
3841
* - :ref:`sphx_glr_gallery_basic_plot_3d.py` (``../../gallery/basic/plot_3d.py``)
3942
- 00:00.000
@@ -173,6 +176,9 @@ Computation times
173176
* - :ref:`sphx_glr_gallery_style_plot_depthshade.py` (``../../gallery/style/plot_depthshade.py``)
174177
- 00:00.000
175178
- 0.0
179+
* - :ref:`sphx_glr_gallery_style_plot_edge_geometries.py` (``../../gallery/style/plot_edge_geometries.py``)
180+
- 00:00.000
181+
- 0.0
176182
* - :ref:`sphx_glr_gallery_style_plot_edgepadding.py` (``../../gallery/style/plot_edgepadding.py``)
177183
- 00:00.000
178184
- 0.0

gallery/other/plot_filled_edges.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Filled edges
3+
============
4+
5+
Most of the time edges have no "filling", but what if they did? Then you would
6+
get this crazy example.
7+
8+
.. tip::
9+
Edges are not supposed to be filled, use at your own risk!
10+
"""
11+
12+
import networkx as nx
13+
import matplotlib.pyplot as plt
14+
import iplotx as ipx
15+
16+
g = nx.Graph()
17+
g.add_edges_from([(0, 1), (1, 2), (0, 2)])
18+
19+
layout = [(0, 0), (1, 0), (2, 0)]
20+
21+
artist = ipx.network(
22+
g,
23+
layout,
24+
edge_arc=True,
25+
edge_tension=-1,
26+
vertex_facecolor="#005F73",
27+
vertex_edgecolor="#001219",
28+
vertex_linewidth=2,
29+
)[0]
30+
31+
edge_artist = artist.get_edges()
32+
edge_artist.set_facecolors([
33+
"#94D2BD66",
34+
"#EE9B0066",
35+
"#AE201266",
36+
])

gallery/other/plot_multiarc.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Multiarc
3+
========
4+
5+
This example shows how to plot a bunch of arcs.
6+
"""
7+
8+
import igraph as ig
9+
import matplotlib.pyplot as plt
10+
import iplotx as ipx
11+
12+
g = ig.Graph.Ring(4, directed=True)
13+
layout = [[1, 0], [0, 1], [-1, 0], [0, -1]]
14+
15+
ipx.network(
16+
g,
17+
layout,
18+
vertex_labels=True,
19+
aspect=1,
20+
edge_tension=1,
21+
edge_arc=True,
22+
edge_arrow={"marker": ">","width": 6},
23+
edge_linewidth=3,
24+
)

iplotx/edge/geometry.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,15 +466,17 @@ def _compute_edge_path_arc(
466466
)
467467
angle_start = atan2(*(vs[0] - center)[::-1])
468468
angle_end = atan2(*(vs[1] - center)[::-1])
469-
if (np.abs(tension) > 1) and (np.abs(angle_end - angle_start) < np.pi):
470-
if angle_end > angle_start:
471-
angle_start += 2 * np.pi
472-
else:
473-
angle_end += 2 * np.pi
469+
470+
# Figure out how to draw the correct arc of the two
471+
if (tension > 0) and (angle_end < angle_start):
472+
angle_end += 2 * np.pi
473+
elif (tension < 0) and (angle_end > angle_start):
474+
angle_start += 2 * np.pi
475+
474476
# print(f"angle_start: {np.degrees(angle_start):.2f}")
475477
# print(f"angle_end: {np.degrees(angle_end):.2f}")
476478

477-
naux = 30
479+
naux = max(30, int(np.ceil(np.degrees(np.abs(angle_end - angle_start)))) // 3)
478480
angles = np.linspace(angle_start, angle_end, naux + 2)[1:-1]
479481
auxs = center + np.array([np.cos(angles), np.sin(angles)]).T * np.linalg.norm(
480482
vs[0] - center

iplotx/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
iplotx version information module.
33
"""
44

5-
__version__ = "1.4.1"
5+
__version__ = "1.4.2"
545 Bytes
Loading
3.5 KB
Loading
1.9 KB
Loading
23.5 KB
Loading

tests/test_igraph.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def test_directed_arcs(self):
239239
layout = [[0, 0], [1, 0], [2, 0], [3, 0]]
240240

241241
fig, ax = plt.subplots()
242-
ipx.plot(
242+
ipx.graph(
243243
g,
244244
layout=layout,
245245
ax=ax,
@@ -248,6 +248,21 @@ def test_directed_arcs(self):
248248
margins=0.2,
249249
)
250250

251+
@image_comparison(baseline_images=["multiarc45"])
252+
def test_multiarc(self):
253+
g = ig.Graph.Ring(4, directed=True)
254+
layout = [[1, 0], [0, 1], [-1, 0], [0, -1]]
255+
256+
fig, ax = plt.subplots()
257+
ipx.graph(
258+
g,
259+
layout,
260+
ax=ax,
261+
edge_arc=True,
262+
edge_tension=1,
263+
aspect=1,
264+
)
265+
251266

252267
class ClusteringTestRunner(unittest.TestCase):
253268
@property

0 commit comments

Comments
 (0)