亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

具有不同大小圓圈的單列熱圖

具有不同大小圓圈的單列熱圖

動漫人物 2023-06-20 13:21:41
我從此處提供的示例進行擴展。但是,我不知道如何使用帶有 PathCollector 的 NumPy 數組來創建一個熱圖,該熱圖生成一個包含 20 個變量(Term)的單列,圓圈表示大小(Number_Protein)和顏色(P_value_abs)。到目前為止,這是我得到的地方,我們將不勝感激。ylabels = Shared["Term"]xlabels = ["Overlap"]x, y = np.meshgrid(1, 20)s = Shared["Number_Protein"]c = Shared["P_value_abs"]fig, ax = plt.subplots()R = s/s.max()/2circles = [plt.Circle((j,i), radius=r) for r, j, i in zip(R, x, y)]col = PatchCollection(circles, array=c, cmap="coolwarm")ax.add_collection(col)ax.set(xticklabels=xlabels, yticklabels=ylabels)fig.colorbar(col)plt.show()
查看完整描述

1 回答

?
jeck貓

TA貢獻1909條經驗 獲得超7個贊

問題的確切目標有點難以猜測。這是一個嘗試:


import pandas as pd

from matplotlib import pyplot as plt

from matplotlib.collections import PatchCollection

import numpy as np


Shared = pd.DataFrame({'Term': ['Term{i}' for i in range(1, 7)],

? ? ? ? ? ? ? ? ? ? ? ?'Number_Protein': np.random.randint(150, 220, 6),

? ? ? ? ? ? ? ? ? ? ? ?'P_value_abs': np.random.uniform(50, 95, 6)})

ylabels = Shared["Term"]

xlabels = ["Overlap"]


s = Shared["Number_Protein"]

c = Shared["P_value_abs"]

norm = plt.Normalize(c.min(), c.max())


fig, ax = plt.subplots()


R = s / s.max() / 2

circles = [plt.Circle((0, i), radius=r) for i, r in enumerate(R)]

col = PatchCollection(circles, array=c, cmap="coolwarm", norm=norm)

ax.add_collection(col)


ax.set_xticks([0])

ax.set_xticklabels(xlabels)

ax.set_yticks(range(len(R)))

ax.set_yticklabels(ylabels)

ax.set_xlim(-0.5, 0.5)

ax.set_ylim(-0.5, len(ylabels)-0.5 )

ax.set_aspect('equal')

fig.colorbar(col)

plt.show()

http://img1.sycdn.imooc.com/649137a1000107ca03250238.jpg

這將創建一個圖,圓的半徑與“Number_Protein”成比例,顏色與“P_value_abs”相關。請注意,當顏色值不在零和一之間時,norm需要將原始值轉換為該范圍。



查看完整回答
反對 回復 2023-06-20
  • 1 回答
  • 0 關注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號