Reputation: 149
I want to make a subplot for a heatmap where the y-axis matches that of the heatmap (features), but the x axis is some transformation of the mean of the binned values represented for each feature in the heatmap. Below is an example figure:
I can make the heatmap already using imshow, and I have an array of transformed means for each feature with indices that match the heatmap array. How can I produce the subplot on the right of my example figure?
Upvotes: 0
Views: 1785
Reputation: 16249
The two main things are setting up the axes to share the y-metric (sharey=True
) and (as you have) setting up your the transformed data to use the same indices:
import matplotlib.pyplot as plt
from numpy.random import random
from numpy import var
H = random(size=(120,80))
Hvar = var(H, axis=1)
fig, axs = plt.subplots(figsize=(3,3), ncols=2, sharey=True, sharex=False)
plt.sca(axs[0])
plt.imshow(H) #heatmap into current axis
axs[0].set_ylim(0,120)
axs[1].scatter(Hvar, range(len(Hvar)))
plt.show()
Upvotes: 2