2

I am not sure what to even call the plot below. A 1D Ribbon plot?

Basically, I want to create something like this (a linear plot with gradient colored boxes by abundance) in a list. Any leads on the name of such a plot or how to visualize abundance in a list would be helpful.

Bonus

If you have thoughts on how to add text above the plot (from a different list or dictionary object) like the image shown that would also be appreciated

Cody Glickman
  • 514
  • 1
  • 8
  • 30
  • 1
    Let's call it a fancy version of an annotated [1D heatmap](https://stackoverflow.com/a/45842334/8881141). I am sure you figure out [how to annotate it](https://matplotlib.org/devdocs/gallery/images_contours_and_fields/image_annotated_heatmap.html). Although if you want cute round corners, you probably have to go back to [creating fancybox patches](https://matplotlib.org/3.2.1/gallery/shapes_and_collections/artist_reference.html#sphx-glr-gallery-shapes-and-collections-artist-reference-py). – Mr. T Nov 12 '20 at 19:57

1 Answers1

3

enter image description here

Here is my approach based on 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()
xjcl
  • 12,848
  • 6
  • 67
  • 89