Arc plot
ต่อไป มาใช้ Arc plot เพื่อแสดงผลโครงข่ายกัน โดยจะได้ฝึกจัดเรียงโหนดในกราฟด้วย
หมายเหตุ: แบบฝึกหัดนี้อาจใช้เวลาประมาณ 4-7 วินาทีในการรันหากทำถูกต้อง
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์เครือข่ายเบื้องต้นด้วย Python
คำแนะนำการฝึกหัด
- สร้าง Arc plot ของโครงข่ายความร่วมมือบน GitHub โดยจัดเรียง author ตาม degree โดยทำตามขั้นตอนต่อไปนี้
- วนซ้ำผ่านโหนดทั้งหมดใน
Gพร้อมกับ metadata (โดยระบุdata=True) - ในแต่ละรอบของลูป ให้คำนวณ degree ของแต่ละโหนด
nด้วยnx.degree()และกำหนดค่าให้กับ attribute'degree'ของโหนดนั้น โดยnx.degree()รับ argument สองตัว ได้แก่ กราฟและโหนด - สร้าง
arcplotaโดยระบุ parameter สองตัว ได้แก่ argumentgraphซึ่งคือGและ argumentsort_byซึ่งคือ'degree'เพื่อจัดเรียงโหนด - แสดงผล
arcplot บนหน้าจอ
- วนซ้ำผ่านโหนดทั้งหมดใน
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import necessary modules
from nxviz import arc
import matplotlib.pyplot as plt
# Iterate over all the nodes in G, including the metadata
for n, d in ____:
# Calculate the degree of each node: G.node[n]['degree']
____ = ____
# Create the Arc plot: a
a = ____
# Draw the Arc plot to the screen
plt.show()