開始使用免費開始

Circos 圖

最後,來為這個網路繪製一張 Circos 圖吧!

本練習屬於課程

Python 網路分析入門

檢視課程

練習說明

  • 為此網路繪製一張 Circos 圖;GitHub 使用者需依 degree 排序,並依其 'grouping' 鍵分組與著色。請依下列步驟進行:
    • 遍歷 G 的所有節點並包含中繼資料(指定 data=True)。
    • 在每次迭代中,使用 nx.degree() 計算每個節點 n 的 degree,並設定其 'degree' 屬性。
    • 建立 circos 圖物件 c,在圖 G 之外再指定三個參數:sort_by 設為 'degree'group_bynode_color_by 皆設為 'grouping'
    • Circos 圖繪製到螢幕上。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import necessary modules
from nxviz import circos
import matplotlib.pyplot as plt

# Iterate over all the nodes, including the metadata
for n, d in ____:

    # Calculate the degree of each node: G.node[n]['degree']
    ____ = ____

# Create the Circos plot: c
c = ____

# Draw the Circos plot to the screen
____
plt.show()
編輯並執行程式碼