如何使用列表值创建颜色梯度一维热图(带状图)?

How to Create a Color Gradient 1D Heatmap (Ribbon Plot) with List Values?

我什至不知道如何称呼下面的情节。一维带状图?

基本上,我想在列表中创建类似这样的东西(带有渐变色框的线性图)。任何关于此类地块名称或如何在列表中可视化丰度的线索都会有所帮助。

奖金

如果您对如何在图表上方添加文本(来自不同的列表或字典对象)有想法,就像显示的图像一样,我们也将不胜感激

这是我基于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()