1 回答
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()
这将创建一个图,圆的半径与“Number_Protein”成比例,颜色与“P_value_abs”相关。请注意,当颜色值不在零和一之间时,norm
需要将原始值转换为该范围。
添加回答
举报