Skip to content

Commit 919fe5d

Browse files
LouieMHLegrandNico
andauthored
add a plot_network method using NetworkX as backende (#275)
* Added plot_network_x function to plots.py folder * Added plot_network_x function to plots.py folder * reorganize the plots module * update documentation * add tests * new lock --------- Co-authored-by: LegrandNico <[email protected]>
1 parent eeacec3 commit 919fe5d

File tree

15 files changed

+926
-676
lines changed

15 files changed

+926
-676
lines changed

docs/source/api.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,32 @@ Plots
203203
*****
204204

205205
Plotting functionalities to visualize parameters trajectories and correlations after
206-
observing new data.
206+
observing new data. We are currently fully supporting Graphviz. NetworkX is also
207+
available for some functions.
207208

208-
.. currentmodule:: pyhgf.plots
209+
Graphviz
210+
========
211+
212+
.. currentmodule:: pyhgf.plots.graphviz
209213

210214
.. autosummary::
211-
:toctree: generated/pyhgf.plots
215+
:toctree: generated/pyhgf.plots.graphviz
212216

213217
plot_trajectories
214218
plot_correlations
215219
plot_network
216220
plot_nodes
217221

222+
Networkx
223+
========
224+
225+
.. currentmodule:: pyhgf.plots.networkx
226+
227+
.. autosummary::
228+
:toctree: generated/pyhgf.plots.networkx
229+
230+
plot_network
231+
218232
Response
219233
********
220234

poetry.lock

Lines changed: 90 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyhgf/model/network.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
add_ef_state,
1818
get_couplings,
1919
)
20-
from pyhgf.plots import plot_correlations, plot_network, plot_nodes, plot_trajectories
20+
from pyhgf.plots import graphviz, networkx
2121
from pyhgf.typing import Attributes, Edges, NetworkParameters, UpdateSequence
2222
from pyhgf.utils import (
2323
add_edges,
@@ -473,19 +473,29 @@ def add_nodes(
473473

474474
def plot_nodes(self, node_idxs: Union[int, List[int]], **kwargs):
475475
"""Plot the node(s) beliefs trajectories."""
476-
return plot_nodes(network=self, node_idxs=node_idxs, **kwargs)
476+
return graphviz.plot_nodes(network=self, node_idxs=node_idxs, **kwargs)
477477

478478
def plot_trajectories(self, **kwargs):
479479
"""Plot the parameters trajectories."""
480-
return plot_trajectories(network=self, **kwargs)
480+
return graphviz.plot_trajectories(network=self, **kwargs)
481481

482482
def plot_correlations(self):
483483
"""Plot the heatmap of cross-trajectories correlation."""
484-
return plot_correlations(network=self)
484+
return graphviz.plot_correlations(network=self)
485485

486-
def plot_network(self):
486+
def plot_network(self, backend: str = "graphviz"):
487487
"""Visualization of node network using GraphViz."""
488-
return plot_network(network=self)
488+
if backend == "graphviz":
489+
return graphviz.plot_network(network=self)
490+
elif backend == "networkx":
491+
return networkx.plot_network(network=self)
492+
else:
493+
raise ValueError(
494+
(
495+
"Invalid backend."
496+
" Should be one of the following: 'graphviz' or 'networkx'",
497+
)
498+
)
489499

490500
def to_pandas(self) -> pd.DataFrame:
491501
"""Export the nodes trajectories and surprise as a Pandas data frame.

0 commit comments

Comments
 (0)