iplotx 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ # This workflow will upload a Python Package to PyPI when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ release-build:
20
+ runs-on: ubuntu-latest
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - uses: actions/setup-python@v5
26
+ with:
27
+ python-version: "3.x"
28
+
29
+ - name: Build release distributions
30
+ run: |
31
+ # NOTE: put your own distribution build steps here.
32
+ python -m pip install build
33
+ python -m build
34
+
35
+ - name: Upload distributions
36
+ uses: actions/upload-artifact@v4
37
+ with:
38
+ name: release-dists
39
+ path: dist/
40
+
41
+ pypi-publish:
42
+ runs-on: ubuntu-latest
43
+ needs:
44
+ - release-build
45
+ permissions:
46
+ # IMPORTANT: this permission is mandatory for trusted publishing
47
+ id-token: write
48
+
49
+ # Dedicated environments with protections for publishing are strongly recommended.
50
+ # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
51
+ environment:
52
+ name: pypi
53
+ # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
54
+ # url: https://pypi.org/p/YOURPROJECT
55
+ #
56
+ # ALTERNATIVE: if your GitHub Release name is the PyPI project version string
57
+ # ALTERNATIVE: exactly, uncomment the following line instead:
58
+ # url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
59
+
60
+ steps:
61
+ - name: Retrieve release distributions
62
+ uses: actions/download-artifact@v4
63
+ with:
64
+ name: release-dists
65
+ path: dist/
66
+
67
+ - name: Publish release distributions to PyPI
68
+ uses: pypa/gh-action-pypi-publish@release/v1
69
+ with:
70
+ packages-dir: dist/
@@ -0,0 +1,41 @@
1
+ # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3
+
4
+ name: Python package
5
+
6
+ on:
7
+ push:
8
+ branches: [ "main" ]
9
+ pull_request:
10
+ branches: [ "main" ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
20
+
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+
24
+ - name: Install uv
25
+ uses: astral-sh/setup-uv@v5
26
+ with:
27
+ python-version: ${{ matrix.python-version }}
28
+
29
+ - name: Set up Python ${{ matrix.python-version }}
30
+ uses: actions/setup-python@v5
31
+ with:
32
+ python-version: ${{ matrix.python-version }}
33
+
34
+ - name: Install the project
35
+ run: uv sync --all-extras --group test
36
+
37
+ - name: Run pytest
38
+ run: uv run pytest tests
39
+
40
+ - name: Run flake8
41
+ run: uv run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
@@ -0,0 +1,177 @@
1
+ # Test images
2
+ result_images
3
+
4
+ # Byte-compiled / optimized / DLL files
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+
9
+ # C extensions
10
+ *.so
11
+
12
+ # Distribution / packaging
13
+ .Python
14
+ build/
15
+ develop-eggs/
16
+ dist/
17
+ downloads/
18
+ eggs/
19
+ .eggs/
20
+ lib/
21
+ lib64/
22
+ parts/
23
+ sdist/
24
+ var/
25
+ wheels/
26
+ share/python-wheels/
27
+ *.egg-info/
28
+ .installed.cfg
29
+ *.egg
30
+ MANIFEST
31
+
32
+ # PyInstaller
33
+ # Usually these files are written by a python script from a template
34
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
35
+ *.manifest
36
+ *.spec
37
+
38
+ # Installer logs
39
+ pip-log.txt
40
+ pip-delete-this-directory.txt
41
+
42
+ # Unit test / coverage reports
43
+ htmlcov/
44
+ .tox/
45
+ .nox/
46
+ .coverage
47
+ .coverage.*
48
+ .cache
49
+ nosetests.xml
50
+ coverage.xml
51
+ *.cover
52
+ *.py,cover
53
+ .hypothesis/
54
+ .pytest_cache/
55
+ cover/
56
+
57
+ # Translations
58
+ *.mo
59
+ *.pot
60
+
61
+ # Django stuff:
62
+ *.log
63
+ local_settings.py
64
+ db.sqlite3
65
+ db.sqlite3-journal
66
+
67
+ # Flask stuff:
68
+ instance/
69
+ .webassets-cache
70
+
71
+ # Scrapy stuff:
72
+ .scrapy
73
+
74
+ # Sphinx documentation
75
+ docs/_build/
76
+
77
+ # PyBuilder
78
+ .pybuilder/
79
+ target/
80
+
81
+ # Jupyter Notebook
82
+ .ipynb_checkpoints
83
+
84
+ # IPython
85
+ profile_default/
86
+ ipython_config.py
87
+
88
+ # pyenv
89
+ # For a library or package, you might want to ignore these files since the code is
90
+ # intended to run in multiple environments; otherwise, check them in:
91
+ # .python-version
92
+
93
+ # pipenv
94
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
96
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
97
+ # install all needed dependencies.
98
+ #Pipfile.lock
99
+
100
+ # UV
101
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
102
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
103
+ # commonly ignored for libraries.
104
+ #uv.lock
105
+
106
+ # poetry
107
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
108
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
109
+ # commonly ignored for libraries.
110
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
111
+ #poetry.lock
112
+
113
+ # pdm
114
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
115
+ #pdm.lock
116
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
117
+ # in version control.
118
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
119
+ .pdm.toml
120
+ .pdm-python
121
+ .pdm-build/
122
+
123
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
124
+ __pypackages__/
125
+
126
+ # Celery stuff
127
+ celerybeat-schedule
128
+ celerybeat.pid
129
+
130
+ # SageMath parsed files
131
+ *.sage.py
132
+
133
+ # Environments
134
+ .env
135
+ .venv
136
+ env/
137
+ venv/
138
+ ENV/
139
+ env.bak/
140
+ venv.bak/
141
+
142
+ # Spyder project settings
143
+ .spyderproject
144
+ .spyproject
145
+
146
+ # Rope project settings
147
+ .ropeproject
148
+
149
+ # mkdocs documentation
150
+ /site
151
+
152
+ # mypy
153
+ .mypy_cache/
154
+ .dmypy.json
155
+ dmypy.json
156
+
157
+ # Pyre type checker
158
+ .pyre/
159
+
160
+ # pytype static type analyzer
161
+ .pytype/
162
+
163
+ # Cython debug symbols
164
+ cython_debug/
165
+
166
+ # PyCharm
167
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
168
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
169
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
170
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
171
+ #.idea/
172
+
173
+ # Ruff stuff:
174
+ .ruff_cache/
175
+
176
+ # PyPI configuration file
177
+ .pypirc
iplotx-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 fabilab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ prune .git
2
+ prune .github
3
+
4
+ include iplotx
5
+ include MANIFEST.in
6
+ include tests/*.py
7
+
8
+ graft doc
9
+ prune doc/html
10
+ prune doc/source/tutorials
11
+
12
+ global-exclude .dockerignore .DS_Store .gitattributes .gitignore .gitmodules
13
+
iplotx-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,44 @@
1
+ Metadata-Version: 2.4
2
+ Name: iplotx
3
+ Version: 0.0.1
4
+ Summary: Plot networkx from igraph and networkx.
5
+ Project-URL: Homepage, https://github.com/fabilab/iplotx
6
+ Project-URL: Documentation, https://readthedocs.org/iplotx
7
+ Project-URL: Repository, https://github.com/fabilab/iplotx.git
8
+ Project-URL: Bug Tracker, https://github.com/fabilab/iplotx/issues
9
+ Project-URL: Changelog, https://github.com/fabilab/iplotx/blob/main/CHANGELOG.md
10
+ Author-email: Fabio Zanini <fabio.zanini@unsw.edu.au>
11
+ Maintainer-email: Fabio Zanini <fabio.zanini@unsw.edu.au>
12
+ License: MIT
13
+ Keywords: graph,network,plotting,visualisation
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: matplotlib>=2.0.0
23
+ Requires-Dist: pandas>=2.0.0
24
+ Provides-Extra: igraph
25
+ Requires-Dist: igraph>=0.11.0; extra == 'igraph'
26
+ Provides-Extra: networkx
27
+ Requires-Dist: networkx>=2.0.0; extra == 'networkx'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # iplotx
31
+ Plotting networks from igraph and networkx.
32
+
33
+ **NOTE**: This is currently pre-alpha quality software. The API and functionality will break constantly, so use at your own risk. That said, if you have things you would like to see improved, please open a GitHub issue.
34
+
35
+ ## Roadmap
36
+ - Plot networks from igraph and networkx interchangeably, using matplotlib as a backend. ✅
37
+ - Support interactive plotting, e.g. zooming and panning after the plot is created. ✅
38
+ - Support storing the plot to disk thanks to the many matplotlib backends (SVG, PNG, PDF, etc.).
39
+ - Efficient plotting of large graphs using matplotlib's collection functionality. ✅ (partially)
40
+ - Support animations, e.g. showing the evolution of a network over time. 🏗️
41
+ - Support uni- and bi-directional communication between graph object and plot object.🏗️
42
+
43
+ ## Authors
44
+ Fabio Zanini (https://fabilab.org)
iplotx-0.0.1/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # iplotx
2
+ Plotting networks from igraph and networkx.
3
+
4
+ **NOTE**: This is currently pre-alpha quality software. The API and functionality will break constantly, so use at your own risk. That said, if you have things you would like to see improved, please open a GitHub issue.
5
+
6
+ ## Roadmap
7
+ - Plot networks from igraph and networkx interchangeably, using matplotlib as a backend. ✅
8
+ - Support interactive plotting, e.g. zooming and panning after the plot is created. ✅
9
+ - Support storing the plot to disk thanks to the many matplotlib backends (SVG, PNG, PDF, etc.).
10
+ - Efficient plotting of large graphs using matplotlib's collection functionality. ✅ (partially)
11
+ - Support animations, e.g. showing the evolution of a network over time. 🏗️
12
+ - Support uni- and bi-directional communication between graph object and plot object.🏗️
13
+
14
+ ## Authors
15
+ Fabio Zanini (https://fabilab.org)
@@ -0,0 +1,2 @@
1
+ from .version import __version__
2
+ from .plotting import plot
@@ -0,0 +1,122 @@
1
+ import numpy as np
2
+ import matplotlib as mpl
3
+ from matplotlib.patches import PathPatch
4
+
5
+
6
+ def make_arrow_patch(marker: str = "|>", width: float = 8, **kwargs):
7
+ """Make a patch of the given marker shape and size."""
8
+ height = kwargs.pop("height", width * 1.3)
9
+
10
+ if marker == "|>":
11
+ codes = ["MOVETO", "LINETO", "LINETO"]
12
+ path = mpl.path.Path(
13
+ np.array([[-height, width * 0.5], [-height, -width * 0.5], [0, 0]]),
14
+ codes=[getattr(mpl.path.Path, x) for x in codes],
15
+ closed=True,
16
+ )
17
+ elif marker == ">":
18
+ kwargs["facecolor"] = "none"
19
+ if "color" in kwargs:
20
+ kwargs["edgecolor"] = kwargs.pop("color")
21
+ codes = ["MOVETO", "LINETO", "LINETO"]
22
+ path = mpl.path.Path(
23
+ np.array([[-height, width * 0.5], [0, 0], [-height, -width * 0.5]]),
24
+ codes=[getattr(mpl.path.Path, x) for x in codes],
25
+ closed=False,
26
+ )
27
+ elif marker == ">>":
28
+ overhang = kwargs.pop("overhang", 0.25)
29
+ codes = ["MOVETO", "LINETO", "LINETO", "LINETO"]
30
+ path = mpl.path.Path(
31
+ np.array(
32
+ [
33
+ [0, 0],
34
+ [-height, -width * 0.5],
35
+ [-height * (1.0 - overhang), 0],
36
+ [-height, width * 0.5],
37
+ ]
38
+ ),
39
+ codes=[getattr(mpl.path.Path, x) for x in codes],
40
+ closed=True,
41
+ )
42
+ elif marker == ")>":
43
+ overhang = kwargs.pop("overhang", 0.25)
44
+ codes = ["MOVETO", "LINETO", "CURVE3", "CURVE3"]
45
+ path = mpl.path.Path(
46
+ np.array(
47
+ [
48
+ [0, 0],
49
+ [-height, -width * 0.5],
50
+ [-height * (1.0 - overhang), 0],
51
+ [-height, width * 0.5],
52
+ ]
53
+ ),
54
+ codes=[getattr(mpl.path.Path, x) for x in codes],
55
+ closed=True,
56
+ )
57
+ elif marker == ")":
58
+ kwargs["facecolor"] = "none"
59
+ if "color" in kwargs:
60
+ kwargs["edgecolor"] = kwargs.pop("color")
61
+ codes = ["MOVETO", "CURVE3", "CURVE3"]
62
+ path = mpl.path.Path(
63
+ np.array(
64
+ [
65
+ [-height * 0.5, width * 0.5],
66
+ [height * 0.5, 0],
67
+ [-height * 0.5, -width * 0.5],
68
+ ]
69
+ ),
70
+ codes=[getattr(mpl.path.Path, x) for x in codes],
71
+ closed=False,
72
+ )
73
+ elif marker == "d":
74
+ codes = ["MOVETO", "LINETO", "LINETO", "LINETO"]
75
+ path = mpl.path.Path(
76
+ np.array(
77
+ [
78
+ [-height * 0.5, width * 0.5],
79
+ [-height, 0],
80
+ [-height * 0.5, -width * 0.5],
81
+ [0, 0],
82
+ ]
83
+ ),
84
+ codes=[getattr(mpl.path.Path, x) for x in codes],
85
+ closed=True,
86
+ )
87
+ elif marker == "p":
88
+ codes = ["MOVETO", "LINETO", "LINETO", "LINETO"]
89
+ path = mpl.path.Path(
90
+ np.array(
91
+ [
92
+ [-height, 0],
93
+ [0, 0],
94
+ [0, -width],
95
+ [-height, -width],
96
+ ]
97
+ ),
98
+ codes=[getattr(mpl.path.Path, x) for x in codes],
99
+ closed=True,
100
+ )
101
+ elif marker == "q":
102
+ codes = ["MOVETO", "LINETO", "LINETO", "LINETO"]
103
+ path = mpl.path.Path(
104
+ np.array(
105
+ [
106
+ [-height, 0],
107
+ [0, 0],
108
+ [0, width],
109
+ [-height, width],
110
+ ]
111
+ ),
112
+ codes=[getattr(mpl.path.Path, x) for x in codes],
113
+ closed=True,
114
+ )
115
+
116
+ patch = PathPatch(
117
+ path,
118
+ **kwargs,
119
+ )
120
+ return patch
121
+
122
+ raise KeyError(f"Unknown marker: {marker}")
@@ -0,0 +1,47 @@
1
+ from math import pi
2
+ import numpy as np
3
+
4
+
5
+ def _compute_loops_per_angle(nloops, angles):
6
+ if len(angles) == 0:
7
+ return [(0, 2 * pi, nloops)]
8
+
9
+ angles_sorted_closed = list(sorted(angles))
10
+ angles_sorted_closed.append(angles_sorted_closed[0] + 2 * pi)
11
+ deltas = np.diff(angles_sorted_closed)
12
+
13
+ # Now we have the deltas and the total number of loops
14
+ # 1. Assign all loops to the largest wedge
15
+ idx_dmax = deltas.argmax()
16
+ if nloops == 1:
17
+ return [
18
+ (angles_sorted_closed[idx_dmax], angles_sorted_closed[idx_dmax + 1], nloops)
19
+ ]
20
+
21
+ # 2. Check if any other wedges are larger than this
22
+ # If not, we are done (this is the algo in igraph)
23
+ dsplit = deltas[idx_dmax] / nloops
24
+ if (deltas > dsplit).sum() < 2:
25
+ return [
26
+ (angles_sorted_closed[idx_dmax], angles_sorted_closed[idx_dmax + 1], nloops)
27
+ ]
28
+
29
+ # 3. Check how small the second-largest wedge would become
30
+ idx_dsort = np.argsort(deltas)
31
+ return [
32
+ (
33
+ angles_sorted_closed[idx_dmax],
34
+ angles_sorted_closed[idx_dmax + 1],
35
+ nloops - 1,
36
+ ),
37
+ (
38
+ angles_sorted_closed[idx_dsort[-2]],
39
+ angles_sorted_closed[idx_dsort[-2] + 1],
40
+ 1,
41
+ ),
42
+ ]
43
+
44
+ ## TODO: we should greedily iterate from this
45
+ ## TODO: finish this
46
+ # dsplit_new = dsplit * nloops / (nloops - 1)
47
+ # dsplit2_new = deltas[idx_dsort[-2]]