행위

"김어진 과제.lst"의 두 판 사이의 차이

KHS DH wiki

1번째 줄: 1번째 줄:
import networkx as nx
+
<pre>
import matplotlib.pyplot as plt
+
#Project
 +
h1 나의 첫번째 네트워크 그래프
 +
 
 +
#Class
 +
사람
 +
음식
 +
미디어
 +
취미
 +
대학원
 +
 
 +
#Relation
 +
belong to
 +
likes
 +
watched
 +
used to
  
# 데이터 로드
 
data = """
 
 
#Nodes
 
#Nodes
 
001 사람 김어진
 
001 사람 김어진
28번째 줄: 40번째 줄:
 
022    취미    영화보기
 
022    취미    영화보기
 
023    취미    노래듣기
 
023    취미    노래듣기
 +
024    대학원  대학원 
  
 
#Links
 
#Links
56번째 줄: 69번째 줄:
 
001 022 used to
 
001 022 used to
 
001 023 used to
 
001 023 used to
"""
 
 
# 데이터 처리
 
nodes = {}
 
for line in data.split('\n'):
 
    if line.strip() == '':
 
        continue
 
    parts = line.split('\t')
 
    node_id = parts[0]
 
    node_class = parts[1].strip()
 
    node_name = parts[2].strip()
 
    nodes[node_id] = {'class': node_class, 'name': node_name}
 
 
G = nx.Graph()
 
 
# 노드 추가
 
for node_id, node_data in nodes.items():
 
    G.add_node(node_id, class=node_data['class'], name=node_data['name'])
 
 
# 링크 추가
 
links = [
 
    (link.split('\t')[0], link.split('\t')[1])
 
    for link in data.split('\n') if 'Links' not in link and link.strip() != ''
 
]
 
 
for link in links:
 
    G.add_edge(link[0], link[1])
 
 
# 그래프 시각화
 
plt.figure(figsize=(10, 8))
 
 
pos = nx.spring_layout(G)  # 그래프의 위치 결정
 
 
node_colors = {'사람': 'blue', '음식': 'green', '미디어': 'red', '취미': 'yellow'}
 
node_color = [node_colors[data['class']] for node, data in G.nodes(data=True)]
 
nx.draw(G, pos, with_labels=True, node_color=node_color, node_size=500, font_size=10)
 
 
plt.title("네트워크 그래프")
 
plt.show()
 
  
 +
#End
 +
</pre>
 
==Visualisation==
 
==Visualisation==
 
{{NetworkGraph | title=김어진_과제.lst}}
 
{{NetworkGraph | title=김어진_과제.lst}}
  
 
  [[분류:Knuch:김어진]] [[분류:문화기술개론]] [[분류:한국전통문화대학교]]
 
  [[분류:Knuch:김어진]] [[분류:문화기술개론]] [[분류:한국전통문화대학교]]

2024년 3월 20일 (수) 01:42 판

#Project
h1 나의 첫번째 네트워크 그래프

#Class
사람
음식
미디어
취미
대학원

#Relation
belong to
likes
watched
used to

#Nodes
001	사람	김어진
002	사람	신현빈
003	사람	임서연
004	사람	변혜빈
005	사람	강혜리
006	사람	박도연
007	사람	김수현
008	사람	선은혁
009	사람    이종욱 
010     음식	샐러드
011	음식	샤브샤브
012	음식	구움과자
013	음식	집밥
014	미디어	DUNE:PART2
015	미디어	닭강정
016	미디어	눈물의 여왕
017	미디어	웨딩파서블
018     취미    고양이랑놀기
019     취미    맛집찾기
020     취미    음식사진찍기
021     취미    멍때리기
022     취미    영화보기
023     취미    노래듣기
024     대학원  대학원  

#Links
001	024	belong to
002	024	belong to
003	024	belong to
004	024	belong to
005	024	belong to
006	024	belong to
007	024	belong to
008	024	belong to
009	024	belong to
001	010	likes
001	011	likes
001	012	likes
001	013	likes
001	014	watched
002	014	watched
003	014	watched
005	014	watched
006	014	watched
007	014	watched
008	014	watched
001	018	used to
001	019	used to
001	020	used to
001	021	used to
001	022	used to
001	023	used to

#End

Visualisation