MCPcopy Create free account
hub / github.com/MIT-SPARK/Clio / draw_task_clusters

Function draw_task_clusters

clio_batch/cluster_plotting.py:57–84  ·  view source on GitHub ↗

Draw clusters colored by nearest task.

(
    ax,
    G,
    ws,
    score,
    edge_color=(0.22, 0.22, 0.22, 0.4),
    node_size=40,
    edge_width=0.5,
    pastel_factor=0.7,
    **kwargs,
)

Source from the content-addressed store, hash-verified

55
56
57def draw_task_clusters(
58 ax,
59 G,
60 ws,
61 score,
62 edge_color=(0.22, 0.22, 0.22, 0.4),
63 node_size=40,
64 edge_width=0.5,
65 pastel_factor=0.7,
66 **kwargs,
67):
68 """Draw clusters colored by nearest task."""
69 pos = {x: G.nodes[x]["position"][:2] for x in G}
70 cmap = distinctipy.get_colors(len(score.tasks), pastel_factor=pastel_factor)
71
72 cluster_features = np.array(ws.get_merged_features(G, f_score=score))
73 best_tasks = score.get_best_tasks(cluster_features)
74
75 cmap_lookup = {x: cmap[best_tasks[i]] for i, x in ws.cluster_ids.items()}
76 colors = [cmap_lookup[ws.clusters[ws.order[x]]] for x in G]
77 nx.draw_networkx_edges(G, pos, edge_color=edge_color, width=edge_width, ax=ax)
78 nx.draw_networkx_nodes(G, pos, node_color=colors, node_size=node_size, ax=ax)
79
80 patches = [matplotlib.patches.Patch(edgecolor="k", facecolor=c) for c in cmap]
81 ax.legend(
82 patches, score.tasks, loc="lower left", ncol=3, bbox_to_anchor=(-0.5, -0.15)
83 )
84 ax.set_aspect("equal")
85
86
87def draw_best_tasks(

Callers

nothing calls this directly

Calls 2

get_merged_featuresMethod · 0.80
get_best_tasksMethod · 0.80

Tested by

no test coverage detected