我不知道该怎么称呼下面的情节。一维带状图?
基本上,我想在列表中创建类似的内容(带有按丰度排列的渐变颜色框的线性图)。任何关于此类图的名称或如何可视化列表中的丰度的线索都会有所帮助。
奖金
如果您对如何在绘图上方添加文本(来自不同的列表或字典对象)有想法,如所示的图像,我们也将不胜感激
最佳答案
这是我基于pcolor
的方法:
import numpy as np
import matplotlib.pyplot as plt
labels = ['All cellular component', 'extracellular region', 'plasm membrane',
'synapse', 'cell junction', 'cell protection', 'cytoplasmic vesicle',
'endosome', 'vacuole', 'golgi apparatus', 'endoplasmic reticulum',
'cytosol', 'mitochondrion', 'nucleus', 'chromosome', 'cytoskeleton',
'protein-containing complex', 'other components']
# Dummy values based on word length
values = np.array([[len(l) for l in labels]]) - min(map(len, labels))
fig, ax = plt.subplots()
im = ax.pcolor(np.arange(len(labels)+1) - .5, [0, 1], # center xticks like imshow
values, cmap='Blues', edgecolors='grey', linewidths=1)
for spine in ax.spines.values():
spine.set_edgecolor('grey')
ax.set_xticklabels(labels)
ax.set_xticks( np.arange(len(labels)) ) # Show all data
ax.set_yticks([]) # No Y axis
ax.xaxis.tick_top() # Put labels on top
plt.xticks(rotation=45, ha="left", rotation_mode="anchor") # Rotate labels 45 deg
plt.axis('scaled') # square pixels
ax.tick_params(axis='both', which='both', length=0) # Hide ticks
fig.tight_layout()
plt.show()
关于python - 如何使用列表值创建颜色渐变一维热图(带状图)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64809972/