我知道有像 Plotly 这样的包,但这些包似乎专用于具有带状连接,而不是事物线。我也知道Circos,但似乎很难做出相对简单的东西。
有一个我可以使用的直接的 Python 2.7 脚本(在线示例或在线工具)吗?
我也想知道如何制作这样的图表。
我还在谷歌图片上搜索了你的图片,发现了一些带有这样的视觉效果的论文,但没有说明他们是如何制作的。
我还问了 chatGDP,这是它给我的:
import matplotlib.pyplot as plt
import networkx as nx
import pandas as pd
import numpy as np
# Example data
edges = [
('KP1513', 'GP1521'), ('KP1513', 'GP2243'), ('KP1412', 'GP1521'),
('GP641', 'GP913'), ('GP5979', 'KP1070'), ('GP5056', 'GP1034'),
('GP4715', 'KP730'), ('GP4263', 'KP748'), ('GP4217', 'KP993'),
('GP4123', 'GP1132'), ('GP4007', 'GP3040'), ('GP2876', 'GP408'),
('KP808', 'GP555'), ('KP808', 'GP5881'), ('KP808', 'GP5930'),
('KP808', 'GP6291'), ('KP651', 'KP1789'), ('KP651', 'KP905'),
('KP651', 'KP579'), ('KP651', 'KP682'), ('KP815', 'KP905'),
('KP815', 'KP1933'), ('KP815', 'KP1789'), ('KP815', 'KP579'),
('KP1988', 'GP4263'), ('KP1988', 'GP4217'), ('KP1988', 'GP4123'),
('KP1988', 'GP4007')
]
# Create a graph
G = nx.Graph()
G.add_edges_from(edges)
# Assign groups to nodes
group_assignments = {
'KP1513': 'blue', 'KP1412': 'blue', 'GP641': 'blue', 'GP5979': 'blue', 'GP5056': 'blue',
'GP4715': 'red', 'GP4263': 'red', 'GP4217': 'red', 'GP4123': 'red', 'GP4007': 'red',
'GP2876': 'yellow', 'KP808': 'yellow', 'KP651': 'yellow', 'KP815': 'yellow', 'KP1988': 'yellow',
'GP1521': 'orange', 'GP2243': 'orange', 'GP913': 'orange', 'KP1070': 'orange', 'GP1034': 'orange',
'KP730': 'green', 'KP748': 'green', 'KP993': 'green', 'GP1132': 'green', 'GP3040': 'green',
'GP408': 'purple', 'GP555': 'purple', 'GP5881': 'purple', 'GP5930': 'purple', 'GP6291': 'purple',
'KP1789': 'pink', 'KP905': 'pink', 'KP579': 'pink', 'KP682': 'pink', 'KP1933': 'pink'
}
# Assign node colors based on groups
node_colors = [group_assignments[node] for node in G.nodes]
# Create circular layout with grouped nodes
def grouped_circular_layout(G, group_assignments):
groups = {}
for node, group in group_assignments.items():
if group not in groups:
groups[group] = []
groups[group].append(node)
pos = {}
angle_step = 2 * np.pi / len(G.nodes)
current_angle = 0
for group_nodes in groups.values():
for node in group_nodes:
pos[node] = (np.cos(current_angle), np.sin(current_angle))
current_angle += angle_step
return pos
pos = grouped_circular_layout(G, group_assignments)
# Draw the graph
plt.figure(figsize=(12, 12))
nx.draw(G, pos, with_labels=True, node_size=700, node_color=node_colors, edge_color='gray', linewidths=1.5, font_size=10, font_color='black', font_weight='bold')
plt.title("Chord Diagram with Grouped and Color-Coded Nodes")
plt.show()