我有一個僅包含非數字資料的 DataFrame。我有兩個示例序列:
seq_1 = 'AATGMAM'
seq_2 = 'TATAMTM'
其中這些序列之一用作列,第二個用作索引。如果字母重疊,則 DataFrame 用“*”符號填充。否則,該值為''。
data = [["*" if p1 == p2 else "" for p2 in seq_2] for p1 in seq_1]
df = pd.DataFrame(data, columns=list(seq_1), index=list(seq_2)
A A T G M A M
T *
A * * *
T *
A * * *
M
T *
M * *
現在我想創建一個散點圖來描述這個 DataFrame。x 軸應該是索引,y 軸應該是列。我怎樣才能做到這一點?
編輯:感謝@Shaido,我能夠繪制它。但是,我在為每個標簽添加單獨的顏色時遇到問題。
color_keys = max([np.unique(df.index), np.unique(df.columns)], key=len)
rgb_values = sns.color_palette("Set2", len(color_keys))
colors = dict(zip(color_keys, rgb_values))
for g in np.unique(df.index):
ix = np.where(df.columns == g)
plt.scatter(x[ix], y[ix], c = colors[g], label = g, s = 100)
plt.xticks(np.arange(df.shape[0]), df.index)
plt.yticks(np.arange(df.shape[1]), df.columns)
plt.legend()
plt.show()
如何將每個唯一值映射到單獨的列?
uj5u.com熱心網友回復:
您可以使用 獲得散點圖的坐標
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/374578.html
標籤:Python 熊猫 matplotlib 阴谋 分散
上一篇:從零到曲線的漸變填充
