Skip to content

Commit

Permalink
Add little outgoing edges from terminal nodes (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
caiw authored Sep 27, 2024
1 parent cd1a384 commit 0ebb9da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
28 changes: 14 additions & 14 deletions demos/demo_ippm.ipynb

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion kymata/ippm/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@ def plot_ippm(
def __get_label(inc_edge: str) -> str:
try:
# assumes inc edge is named as transform-x.
label = inc_edge[:inc_edge.index("-")]
label = inc_edge[:inc_edge.rindex("-")]
return label
except ValueError:
# "-" not found in inc_edge. Therefore, it must be input transform.
return inc_edge

non_terminal = set()
for node in graph.values():
non_terminal.update(node.inc_edges)

def __is_terminal_node(inc_edge: str) -> bool:
"""Returns whether the named node is a terminal node in the graph"""
return inc_edge not in non_terminal

# first lets aggregate all the information.
node_x = list(range(len(graph.keys()))) # x coordinates for nodes eg. (x, y) = (node_x[i], node_y[i])
Expand Down Expand Up @@ -116,6 +124,15 @@ def __get_label(inc_edge: str) -> str:

ax.scatter(x=node_x, y=node_y, c=node_colors, s=node_sizes, marker="H", zorder=2)

# Show lines trailing off into the future from terminal nodes
future_width = 20 # ms
for node in graph.keys():
if __is_terminal_node(node):
step_1 = max(node_x) + future_width / 2
step_2 = max(node_x) + future_width
ax.plot([graph[node].position.x, step_1], [graph[node].position.y, graph[node].position.y], color=colors[__get_label(node)], linewidth=linewidth, linestyle="solid")
ax.plot([step_1, step_2], [graph[node].position.y, graph[node].position.y], color=colors[__get_label(node)], linewidth=linewidth, linestyle="dotted")

if title is not None:
plt.title(title)

Expand Down

0 comments on commit 0ebb9da

Please sign in to comment.