Coverage for src/cell_abm_pipeline/tasks/make_graph_figure.py: 0%
21 statements
« prev ^ index » next coverage.py v7.1.0, created at 2024-06-05 19:14 +0000
« prev ^ index » next coverage.py v7.1.0, created at 2024-06-05 19:14 +0000
1import matplotlib.figure as mpl
2import matplotlib.pyplot as plt
3import pandas as pd
4from prefect import task
7@task
8def make_graph_figure(
9 node_data: pd.DataFrame, edge_data: pd.DataFrame, colormap: str
10) -> mpl.Figure:
11 fig = plt.figure(figsize=(4, 4), constrained_layout=True)
13 ax = fig.add_subplot()
14 ax.set_box_aspect(1)
15 ax.invert_yaxis()
16 ax.get_xaxis().set_ticks([])
17 ax.get_yaxis().set_ticks([])
19 for spine in ax.spines.values():
20 spine.set_edgecolor("#dddddd")
22 node_data = node_data.set_index("id")
24 for edge in edge_data.to_dict("records"):
25 x1, y1 = node_data.loc[edge["id1"]][["x", "y"]]
26 x2, y2 = node_data.loc[edge["id2"]][["x", "y"]]
28 ax.plot([x1, x2], [y1, y2], color="k", lw=0.5, zorder=1)
30 ax.scatter(node_data["x"], node_data["y"], c=node_data["v"], cmap=colormap, s=20)
32 return fig