hiveplotlib 0.23.0__tar.gz → 0.25.0__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.
Files changed (32) hide show
  1. {hiveplotlib-0.23.0/src/hiveplotlib.egg-info → hiveplotlib-0.25.0}/PKG-INFO +31 -9
  2. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/README.md +18 -4
  3. hiveplotlib-0.25.0/pyproject.toml +156 -0
  4. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/setup.py +4 -0
  5. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/axis.py +7 -9
  6. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/converters.py +4 -3
  7. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/datasets/__init__.py +114 -16
  8. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/hiveplot.py +172 -148
  9. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/node.py +41 -44
  10. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/p2cp.py +46 -58
  11. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/utils.py +2 -1
  12. hiveplotlib-0.25.0/src/hiveplotlib/viz/base.py +165 -0
  13. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/viz/bokeh.py +45 -76
  14. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/viz/datashader.py +19 -16
  15. hiveplotlib-0.25.0/src/hiveplotlib/viz/holoviews.py +717 -0
  16. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/viz/input_checks.py +12 -12
  17. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/viz/matplotlib.py +78 -91
  18. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/viz/plotly.py +58 -85
  19. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0/src/hiveplotlib.egg-info}/PKG-INFO +31 -9
  20. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib.egg-info/SOURCES.txt +1 -0
  21. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib.egg-info/requires.txt +13 -3
  22. hiveplotlib-0.23.0/pyproject.toml +0 -97
  23. hiveplotlib-0.23.0/src/hiveplotlib/viz/base.py +0 -61
  24. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/LICENSE +0 -0
  25. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/MANIFEST.in +0 -0
  26. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/setup.cfg +0 -0
  27. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/__init__.py +0 -0
  28. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/datasets/trade_data_harvard_growth_lab/international_exports_2019_8112.csv +0 -0
  29. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/datasets/trade_data_harvard_growth_lab/international_exports_metadata_2019_8112.json +0 -0
  30. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib/viz/__init__.py +0 -0
  31. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib.egg-info/dependency_links.txt +0 -0
  32. {hiveplotlib-0.23.0 → hiveplotlib-0.25.0}/src/hiveplotlib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hiveplotlib
3
- Version: 0.23.0
3
+ Version: 0.25.0
4
4
  Summary: Visualize Network Data with Hive Plots
5
5
  Author-email: Gary Koplik <gary.koplik@geomdata.com>
6
6
  License: Copyright (c) 2020 - 2023, Geometric Data Analytics, Inc.
@@ -31,7 +31,7 @@ License: Copyright (c) 2020 - 2023, Geometric Data Analytics, Inc.
31
31
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
32
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33
33
  THE POSSIBILITY OF SUCH DAMAGE.
34
- Project-URL: Documentation, https://geomdata.gitlab.io/hiveplotlib/
34
+ Project-URL: Documentation, https://hiveplotlib.readthedocs.io/stable/
35
35
  Project-URL: Source, https://gitlab.com/geomdata/hiveplotlib
36
36
  Description-Content-Type: text/markdown
37
37
  License-File: LICENSE
@@ -41,13 +41,20 @@ Requires-Dist: pandas
41
41
  Provides-Extra: bokeh
42
42
  Requires-Dist: bokeh; extra == "bokeh"
43
43
  Provides-Extra: datashader
44
+ Requires-Dist: dask[dataframe]; extra == "datashader"
44
45
  Requires-Dist: datashader; extra == "datashader"
45
46
  Requires-Dist: seaborn; extra == "datashader"
46
47
  Provides-Extra: dev
47
48
  Requires-Dist: bokeh; extra == "dev"
49
+ Requires-Dist: cartopy; extra == "dev"
48
50
  Requires-Dist: datashader; extra == "dev"
51
+ Requires-Dist: geopandas; extra == "dev"
52
+ Requires-Dist: flexitext; extra == "dev"
53
+ Requires-Dist: holoviews; extra == "dev"
49
54
  Requires-Dist: jupyter; extra == "dev"
50
55
  Requires-Dist: networkx; extra == "dev"
56
+ Requires-Dist: plotly; extra == "dev"
57
+ Requires-Dist: pybadges; extra == "dev"
51
58
  Requires-Dist: seaborn; extra == "dev"
52
59
  Requires-Dist: tqdm; extra == "dev"
53
60
  Provides-Extra: docs
@@ -55,25 +62,32 @@ Requires-Dist: nbsphinx; extra == "docs"
55
62
  Requires-Dist: sphinx; extra == "docs"
56
63
  Requires-Dist: sphinx-rtd-theme; extra == "docs"
57
64
  Requires-Dist: toml; extra == "docs"
65
+ Provides-Extra: holoviews
66
+ Requires-Dist: holoviews; extra == "holoviews"
58
67
  Provides-Extra: networkx
59
68
  Requires-Dist: networkx; extra == "networkx"
60
69
  Provides-Extra: plotly
61
70
  Requires-Dist: plotly; extra == "plotly"
71
+ Provides-Extra: ruff
72
+ Requires-Dist: ruff; extra == "ruff"
62
73
  Provides-Extra: testing
63
- Requires-Dist: black[jupyter]; extra == "testing"
64
- Requires-Dist: flake8-docstrings; extra == "testing"
65
- Requires-Dist: Flake8-pyproject; extra == "testing"
66
74
  Requires-Dist: pytest; extra == "testing"
67
75
  Requires-Dist: pytest-cov; extra == "testing"
68
76
  Requires-Dist: pytest-html; extra == "testing"
69
77
  Requires-Dist: pytest-timeout; extra == "testing"
70
78
  Requires-Dist: pytest-xdist; extra == "testing"
71
79
 
72
- ![](https://geomdata.gitlab.io/hiveplotlib/_static/hiveplotlib.svg)
80
+ ![](https://hiveplotlib.readthedocs.io/stable/_static/hiveplotlib.svg)
73
81
 
74
82
  A plotting package for generating and visualizing static Hive Plots in `matplotlib`.
75
83
 
76
- <br>
84
+ ![](https://gitlab.com/geomdata/hiveplotlib/-/raw/22-add-formal-holoviews-support/.gitlab/python_badge.svg)
85
+
86
+ [![](https://gitlab.com/geomdata/hiveplotlib/-/raw/master/.gitlab/matplotlib_badge.svg)](https://matplotlib.org/)
87
+ [![](https://gitlab.com/geomdata/hiveplotlib/-/raw/master/.gitlab/bokeh_badge.svg)](https://docs.bokeh.org/en/latest/)
88
+ [![](https://gitlab.com/geomdata/hiveplotlib/-/raw/master/.gitlab/holoviews_badge.svg)](https://holoviews.org/index.html)
89
+ [![](https://gitlab.com/geomdata/hiveplotlib/-/raw/master/.gitlab/plotly_badge.svg)](https://plotly.com/python/)
90
+ [![](https://gitlab.com/geomdata/hiveplotlib/-/raw/master/.gitlab/datashader_badge.svg)](https://datashader.org/)
77
91
 
78
92
  # Installation
79
93
 
@@ -89,6 +103,14 @@ To uninstall, run:
89
103
  $ pip uninstall hiveplotlib
90
104
  ```
91
105
 
106
+ By default, `hiveplotlib` supports visualization only with the [matplotlib](https://matplotlib.org/) backend, but
107
+ `hiveplotlib` also supports [bokeh](https://docs.bokeh.org/en/latest/), [holoviews](https://holoviews.org/index.html),
108
+ and [plotly](https://plotly.com/python/) visualizations, which can be installed via `pip install hiveplotlib[bokeh]`,
109
+ `pip install hiveplotlib[holoviews]`, and `pip install hiveplotlib[plotly]`, respectively.
110
+
111
+ `hiveplotlib` also supports large network visualization via the [datashader](https://datashader.org/) backend,
112
+ which can be installed as `pip install hiveplotlib[datashader]`.
113
+
92
114
  # Contributing
93
115
 
94
116
  For more on contributing to the project, see [CONTRIBUTING.md](https://gitlab.com/geomdata/hiveplotlib/-/blob/master/CONTRIBUTING.md)
@@ -96,7 +118,7 @@ For more on contributing to the project, see [CONTRIBUTING.md](https://gitlab.co
96
118
  # How to Use and Examples
97
119
 
98
120
  For more on how to use the software and examples, see the
99
- [docs](https://geomdata.gitlab.io/hiveplotlib/index.html).
121
+ [docs](https://hiveplotlib.readthedocs.io/stable/index.html).
100
122
 
101
123
  All the example notebooks are available for download as `jupyter` notebooks in the repository under the
102
124
  [examples](https://gitlab.com/geomdata/hiveplotlib/-/tree/master/examples) directory.
@@ -114,7 +136,7 @@ $ bash install.sh
114
136
  # More on Hive Plots
115
137
 
116
138
  For more on Hive Plots, see our
117
- [Introduction to Hive Plots](https://geomdata.gitlab.io/hiveplotlib/introduction_to_hive_plots.html).
139
+ [Introduction to Hive Plots](https://hiveplotlib.readthedocs.io/stable/introduction_to_hive_plots.html).
118
140
 
119
141
  For additional resources, see:
120
142
 
@@ -1,8 +1,14 @@
1
- ![](https://geomdata.gitlab.io/hiveplotlib/_static/hiveplotlib.svg)
1
+ ![](https://hiveplotlib.readthedocs.io/stable/_static/hiveplotlib.svg)
2
2
 
3
3
  A plotting package for generating and visualizing static Hive Plots in `matplotlib`.
4
4
 
5
- <br>
5
+ ![](https://gitlab.com/geomdata/hiveplotlib/-/raw/22-add-formal-holoviews-support/.gitlab/python_badge.svg)
6
+
7
+ [![](https://gitlab.com/geomdata/hiveplotlib/-/raw/master/.gitlab/matplotlib_badge.svg)](https://matplotlib.org/)
8
+ [![](https://gitlab.com/geomdata/hiveplotlib/-/raw/master/.gitlab/bokeh_badge.svg)](https://docs.bokeh.org/en/latest/)
9
+ [![](https://gitlab.com/geomdata/hiveplotlib/-/raw/master/.gitlab/holoviews_badge.svg)](https://holoviews.org/index.html)
10
+ [![](https://gitlab.com/geomdata/hiveplotlib/-/raw/master/.gitlab/plotly_badge.svg)](https://plotly.com/python/)
11
+ [![](https://gitlab.com/geomdata/hiveplotlib/-/raw/master/.gitlab/datashader_badge.svg)](https://datashader.org/)
6
12
 
7
13
  # Installation
8
14
 
@@ -18,6 +24,14 @@ To uninstall, run:
18
24
  $ pip uninstall hiveplotlib
19
25
  ```
20
26
 
27
+ By default, `hiveplotlib` supports visualization only with the [matplotlib](https://matplotlib.org/) backend, but
28
+ `hiveplotlib` also supports [bokeh](https://docs.bokeh.org/en/latest/), [holoviews](https://holoviews.org/index.html),
29
+ and [plotly](https://plotly.com/python/) visualizations, which can be installed via `pip install hiveplotlib[bokeh]`,
30
+ `pip install hiveplotlib[holoviews]`, and `pip install hiveplotlib[plotly]`, respectively.
31
+
32
+ `hiveplotlib` also supports large network visualization via the [datashader](https://datashader.org/) backend,
33
+ which can be installed as `pip install hiveplotlib[datashader]`.
34
+
21
35
  # Contributing
22
36
 
23
37
  For more on contributing to the project, see [CONTRIBUTING.md](https://gitlab.com/geomdata/hiveplotlib/-/blob/master/CONTRIBUTING.md)
@@ -25,7 +39,7 @@ For more on contributing to the project, see [CONTRIBUTING.md](https://gitlab.co
25
39
  # How to Use and Examples
26
40
 
27
41
  For more on how to use the software and examples, see the
28
- [docs](https://geomdata.gitlab.io/hiveplotlib/index.html).
42
+ [docs](https://hiveplotlib.readthedocs.io/stable/index.html).
29
43
 
30
44
  All the example notebooks are available for download as `jupyter` notebooks in the repository under the
31
45
  [examples](https://gitlab.com/geomdata/hiveplotlib/-/tree/master/examples) directory.
@@ -43,7 +57,7 @@ $ bash install.sh
43
57
  # More on Hive Plots
44
58
 
45
59
  For more on Hive Plots, see our
46
- [Introduction to Hive Plots](https://geomdata.gitlab.io/hiveplotlib/introduction_to_hive_plots.html).
60
+ [Introduction to Hive Plots](https://hiveplotlib.readthedocs.io/stable/introduction_to_hive_plots.html).
47
61
 
48
62
  For additional resources, see:
49
63
 
@@ -0,0 +1,156 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools",
4
+ ]
5
+ build-backend = "setuptools.build_meta"
6
+
7
+ [project]
8
+ name = "hiveplotlib"
9
+ version = "0.25.0"
10
+ authors = [
11
+ {name="Gary Koplik", email="gary.koplik@geomdata.com"}
12
+ ]
13
+ description = "Visualize Network Data with Hive Plots"
14
+ readme = "README.md"
15
+ license = {file = "LICENSE"}
16
+ urls = {Documentation="https://hiveplotlib.readthedocs.io/stable/", Source="https://gitlab.com/geomdata/hiveplotlib" }
17
+
18
+
19
+ dependencies = [
20
+ "matplotlib",
21
+ "numpy",
22
+ "pandas"
23
+ ]
24
+
25
+ [project.optional-dependencies]
26
+
27
+ bokeh = [
28
+ "bokeh"
29
+ ]
30
+
31
+ datashader = [
32
+ "dask[dataframe]", # https://github.com/holoviz/datashader/issues/1319
33
+ "datashader",
34
+ "seaborn"
35
+ ]
36
+
37
+ # developer dependencies
38
+ dev = [
39
+ "bokeh",
40
+ "cartopy",
41
+ "datashader",
42
+ "geopandas",
43
+ "flexitext",
44
+ "holoviews",
45
+ "jupyter",
46
+ "networkx",
47
+ "plotly",
48
+ "pybadges",
49
+ "seaborn",
50
+ "tqdm",
51
+ ]
52
+
53
+ # for building documentation
54
+ docs = [
55
+ "nbsphinx",
56
+ "sphinx",
57
+ "sphinx-rtd-theme",
58
+ "toml"
59
+ ]
60
+
61
+ holoviews = [
62
+ "holoviews"
63
+ ]
64
+
65
+ networkx = [
66
+ "networkx"
67
+ ]
68
+
69
+ plotly = [
70
+ "plotly"
71
+ ]
72
+
73
+ # ruff code hygeine checks
74
+ ruff = [
75
+ "ruff"
76
+ ]
77
+
78
+ testing = [
79
+ "pytest",
80
+ "pytest-cov",
81
+ "pytest-html",
82
+ "pytest-timeout",
83
+ "pytest-xdist"
84
+ ]
85
+
86
+ [tool.setuptools.packages.find]
87
+ where = ["src"]
88
+ include = ["hiveplotlib*"]
89
+
90
+ [tool.ruff]
91
+ # ruff performs our linting and formatting.
92
+ # if you receive an error you don't understand, you can run `ruff rule <error code>` to learn more.
93
+ # the full list of ruff rules are here: https://docs.astral.sh/ruff/rules/
94
+ extend-include = ["*.ipynb", "*.pyi"]
95
+
96
+ # Add files here to be completely skipped by ruff.
97
+ extend-exclude = [
98
+ "docs",
99
+ "sandbox"
100
+ ]
101
+
102
+ line-length = 88
103
+ indent-width = 4
104
+
105
+ output-format = "full"
106
+ target-version = "py311"
107
+
108
+ [tool.ruff.lint]
109
+ extend-ignore = [
110
+ "ANN101", # typing `self` being deprecated (and not particularly useful)
111
+ "ANN003", # don't require type hints on kwargs (too many possible types to be useful)
112
+ "D200", # 1-line docstrings will be tolerated
113
+ "D203", # don't require blank line before class docstring.
114
+ "D212", # require docstring text starts on the next line after the triple quotes.
115
+ "E203", # https://black.readthedocs.io/en/stable/faq.html#why-are-flake8-s-e203-and-w503-violated
116
+ "PD901", # generic `df` name for pandas dataframes will be tolerated
117
+ ]
118
+
119
+ extend-select = [
120
+ "A", # use flake8-builtins (check if variable name shadows python builtin names)
121
+ "ANN", # use flake8-annotations (checks type annotations)
122
+ "ARG", # use flake8-unused-arguments (checks for unused arguments)
123
+ # "B", # use flake8-bugbear (nice for cleaner code, but appears to only work when min Python constraint is 3.9)
124
+ "C4", # use flake8-comprehensions (remove unnecessary literals, generators, lists, etc.)
125
+ "D", # use pydoc style rules
126
+ "E", # use pycodestyle warnings
127
+ "I", # use isort rules
128
+ "ICN", # use flake-import-conventions (checks that imports use standard names)
129
+ "N", # use pep8 naming
130
+ "NPY", # numpy-specific rules
131
+ "PERF", # linter focused on avoiding performance anti-patterns
132
+ "PIE", # use flake8-pie (some misc additional linting)
133
+ "PD", # write pandas code more in line with pd recommendations
134
+ "PT", # use flake8-pytest-style (linting specifically for pytest)
135
+ "RET", # use flake8-return (linting on return / raise)
136
+ "SIM", # use flake8-simplify (helps simplify logic in code)
137
+ "TID", # use flake8-tidy-imports (to prevent relative imports)
138
+ "W", # use pycodestyle warnings
139
+ ]
140
+
141
+ [tool.ruff.lint.pycodestyle]
142
+ # allow docstrings to go longer
143
+ max-line-length = 120
144
+
145
+ [tool.ruff.format]
146
+ # like Black, use double quotes for strings.
147
+ quote-style = "double"
148
+
149
+ # like Black, indent with spaces, rather than tabs.
150
+ indent-style = "space"
151
+
152
+ # like Black, respect magic trailing commas.
153
+ skip-magic-trailing-comma = false
154
+
155
+ # like Black, automatically detect the appropriate line ending.
156
+ line-ending = "auto"
@@ -1,3 +1,7 @@
1
+ """
2
+ Setup.
3
+ """
4
+
1
5
  import setuptools
2
6
 
3
7
  if __name__ == "__main__":
@@ -4,10 +4,12 @@
4
4
  Definition of ``Axis`` instance and helper static methods for generating and working with ``Axis`` instances.
5
5
  """
6
6
 
7
- from hiveplotlib.utils import polar2cartesian
7
+ from typing import Hashable, List, Optional
8
+
8
9
  import numpy as np
9
10
  import pandas as pd
10
- from typing import Hashable, List, Optional
11
+
12
+ from hiveplotlib.utils import polar2cartesian
11
13
 
12
14
 
13
15
  class Axis:
@@ -56,7 +58,7 @@ class Axis:
56
58
  end: float = 5,
57
59
  angle: float = 0,
58
60
  long_name: Optional[Hashable] = None,
59
- ):
61
+ ) -> None:
60
62
  """
61
63
  Initialize ``Axis`` object with start and end positions and angle. Default to axis normalized on [0, 1].
62
64
 
@@ -99,7 +101,7 @@ class Axis:
99
101
 
100
102
  def _set_node_placements(
101
103
  self, x: List[float], y: List[float], node_ids: List[Hashable], rho: List[float]
102
- ):
104
+ ) -> None:
103
105
  """
104
106
  Set ``Axis.node_placements`` to a ``pandas.DataFrame``.
105
107
 
@@ -127,9 +129,7 @@ class Axis:
127
129
  {"x": x, "y": y, "unique_id": node_ids, "rho": rho}
128
130
  )
129
131
 
130
- return None
131
-
132
- def _set_node_placement_label(self, label: Hashable):
132
+ def _set_node_placement_label(self, label: Hashable) -> None:
133
133
  """
134
134
  Set which scalar variable in each ``Node`` instance will be used to place each node on the axis when plotting.
135
135
 
@@ -141,5 +141,3 @@ class Axis:
141
141
  :return: ``None``.
142
142
  """
143
143
  self.node_placement_label = label
144
-
145
- return None
@@ -4,16 +4,17 @@
4
4
  Converters from various data structures to ``hiveplotlib``-ready structures.
5
5
  """
6
6
 
7
+ from typing import List, Tuple
7
8
 
8
- from hiveplotlib import Node
9
9
  import numpy as np
10
- from typing import List, Tuple
10
+
11
+ from hiveplotlib import Node
11
12
 
12
13
  # say the graph type instead of calling `nx.Graph` to keep networkx dep out of this file.
13
14
  NetworkXGraph = "networkx.classes.graph.Graph instance"
14
15
 
15
16
 
16
- def networkx_to_nodes_edges(graph: NetworkXGraph) -> Tuple[List[Node], np.ndarray]:
17
+ def networkx_to_nodes_edges(graph: NetworkXGraph) -> Tuple[List[Node], np.ndarray]: # type: ignore
17
18
  """
18
19
  Take a ``networkx`` graph and return ``hiveplotlib``-friendly data structures.
19
20
 
@@ -17,11 +17,14 @@ For Polar Parallel Coordinates Plots (P2CPs), many datasets are available throug
17
17
  """
18
18
 
19
19
  import json
20
+ from pathlib import Path
21
+ from typing import Dict, Hashable, List, Optional, Tuple, Union
22
+
20
23
  import numpy as np
21
- from hiveplotlib import hive_plot_n_axes, HivePlot, Node
22
24
  import pandas as pd
23
- from pathlib import Path
24
- from typing import Dict, Optional, Tuple, Union
25
+
26
+ from hiveplotlib import P2CP, HivePlot, Node, hive_plot_n_axes, p2cp_n_axes
27
+ from hiveplotlib.node import dataframe_to_node_list
25
28
 
26
29
 
27
30
  def international_trade_data(
@@ -57,10 +60,7 @@ def international_trade_data(
57
60
  # path when grabbing files shipped with hiveplotlib
58
61
  internal_path = Path(__path__[0]).joinpath("trade_data_harvard_growth_lab")
59
62
 
60
- if path is None:
61
- path = internal_path
62
- else:
63
- path = Path(path)
63
+ path = internal_path if path is None else Path(path)
64
64
 
65
65
  # grab the shipped year, hs92 values to present what's available on failure
66
66
  csv_files = [
@@ -77,12 +77,14 @@ def international_trade_data(
77
77
  metadata_path = path.joinpath(
78
78
  f"international_exports_metadata_{year}_{hs92_code}.json"
79
79
  )
80
- assert data_path.exists() and metadata_path.exists(), (
81
- f"Could not find data and / or metadata under specified `path`. If you specified your own path, double check "
82
- f"that the path is correct. Your file names should be "
83
- f"If you are using `hiveplotlib` supported data, note that only the following `year`, "
84
- f"`hs29_code` values are supported:\n{hiveplotlib_supported_values}"
85
- )
80
+
81
+ if not (data_path.exists() and metadata_path.exists()):
82
+ raise ValueError(
83
+ "Could not find data and / or metadata under specified `path`. If you specified your own path, double "
84
+ "check that the path is correct. Your file names should be "
85
+ "If you are using `hiveplotlib` supported data, note that only the following `year`, "
86
+ f"`hs29_code` values are supported:\n{hiveplotlib_supported_values}"
87
+ )
86
88
 
87
89
  data = pd.read_csv(data_path)
88
90
  with open(metadata_path, "r") as openfile:
@@ -141,7 +143,7 @@ def four_gaussian_blobs_3d(
141
143
  # make the labels ints
142
144
  df.Label = df.Label.astype(int)
143
145
  # replace the 4s with 3s so our labels are just range(4)
144
- df.Label.values[df.Label.values == 4] = 3
146
+ df.Label.to_numpy()[df.Label.to_numpy() == 4] = 3
145
147
 
146
148
  return df
147
149
 
@@ -161,7 +163,7 @@ def example_hive_plot(
161
163
  :param num_edges: number of edges to generate.
162
164
  :param seed: random seed to use when generating nodes and edges.
163
165
  :param hive_plot_n_axes_kwargs: additional keyword arguments for the underlying
164
- :py:func:`hiveplotlib.hive_plot.hive_plot_n_axes()` call.
166
+ :py:func:`hiveplotlib.hive_plot_n_axes()` call.
165
167
  :return: resulting ``HivePlot`` instance.
166
168
  """
167
169
  color_dict = {
@@ -187,7 +189,7 @@ def example_hive_plot(
187
189
  node_data = data.to_dict(orient="records")
188
190
 
189
191
  # use the dataframe's index as unique id
190
- node_ids = data.index.values
192
+ node_ids = data.index.to_numpy()
191
193
 
192
194
  nodes = [
193
195
  Node(unique_id=node_id, data=node_data[i]) for i, node_id in enumerate(node_ids)
@@ -217,3 +219,99 @@ def example_hive_plot(
217
219
  hp.add_edge_kwargs(axis_id_1=e1, axis_id_2=e2, color=color_dict[e1][e2])
218
220
 
219
221
  return hp
222
+
223
+
224
+ def example_nodes_and_edges(
225
+ num_nodes: int = 100,
226
+ num_edges: int = 200,
227
+ num_axes: int = 3,
228
+ seed: int = 0,
229
+ ) -> Tuple[List[Node], List[List[Hashable]], np.ndarray]:
230
+ """
231
+ Generate example nodes, node splits (one list of nodes per intended axis), and edges.
232
+
233
+ Each node will have a ``"low"``, ``"med"``, and ``"high"`` value, where these values are randomly generated, and as
234
+ the names suggest, for the resulting values of each node, ``"low"`` < ``"med"`` < ``"high"``.
235
+
236
+ :param num_nodes: how many nodes to randomly generate. Node unique IDs will be the integers 0, 1, ... ,
237
+ ``num_nodes - 1``.
238
+ :param num_edges: how many edges to randomly generate.
239
+ :param num_axes: how many axes into which to partition the randomly generated nodes.
240
+ :param seed: random seed to use when randomly generating node and edge data.
241
+ :return: list of generated ``Node`` instances, a list of ``num_axes`` lists that evenly split the node IDs to be
242
+ allocated to their own axes, and a ``(num_edges, 2)`` shaped array of random edges between nodes.
243
+ """
244
+ rng = np.random.default_rng(seed)
245
+
246
+ # example data
247
+ data = pd.DataFrame(
248
+ np.c_[
249
+ rng.uniform(low=0, high=9.99, size=num_nodes),
250
+ rng.uniform(low=10, high=19.99, size=num_nodes),
251
+ rng.uniform(low=20, high=29.99, size=num_nodes),
252
+ ],
253
+ columns=["low", "med", "high"],
254
+ )
255
+ # make indices a column
256
+ data = data.reset_index()
257
+
258
+ node_list = dataframe_to_node_list(data, unique_id_column="index")
259
+ node_ids = data["index"].to_numpy()
260
+
261
+ # split node allocation equally among planned axes
262
+ node_ids_per_axis = np.split(node_ids, num_axes)
263
+ # coax to list of lists
264
+ node_ids_per_axis = [i.tolist() for i in node_ids_per_axis]
265
+
266
+ edges = rng.choice(node_ids, size=num_edges * 2).reshape(-1, 2)
267
+
268
+ return node_list, node_ids_per_axis, edges
269
+
270
+
271
+ def example_p2cp(
272
+ num_points: int = 50,
273
+ noise: float = 0.5,
274
+ random_seed: int = 0,
275
+ four_colors: Tuple[str, str, str, str] = (
276
+ "#de8f05",
277
+ "#029e73",
278
+ "#cc78bc",
279
+ "#0173b2",
280
+ ),
281
+ **p2cp_n_axes_kwargs,
282
+ ) -> P2CP:
283
+ """
284
+ Generate example P2CP of four gaussian blobs.
285
+
286
+ Points will be generated by calling :py:func:`hiveplotlib.datasets.four_gaussian_blobs_3d()` and turned into a P2CP
287
+ via :py:func:`hiveplotlib.p2cp_n_axes()`.
288
+
289
+ :param num_points: number of points in each Gaussian blob.
290
+ :param noise: noisiness of Gaussian blobs.
291
+ :param random_seed: random seed to generate consistent data between calls.
292
+ :param four_colors: four colors to use for four Gaussian blobs.
293
+ :param p2cp_n_axes_kwargs: additional keyword arguments for the underlying
294
+ :py:func:`hiveplotlib.p2cp_n_axes()` call.
295
+ :return: resulting ``P2CP`` instance.
296
+ """
297
+ # color palette for the blobs
298
+ df = four_gaussian_blobs_3d(
299
+ num_points=num_points,
300
+ noise=noise,
301
+ random_seed=random_seed,
302
+ )
303
+
304
+ # the first (0) blob needs to be plotted last, so let's give it the last label for pandas to sort to plot last
305
+ df.loc[df["Label"] == 0, "Label"] = 4
306
+
307
+ # align the colors with the figure from the paper
308
+ indices_dict = [{"color": color} for color in four_colors]
309
+
310
+ return p2cp_n_axes(
311
+ data=df,
312
+ split_on="Label",
313
+ vmins=[-1] * 3,
314
+ vmaxes=[6] * 3,
315
+ indices_list_kwargs=indices_dict,
316
+ **p2cp_n_axes_kwargs,
317
+ )