I would like to plot several heatmaps side by side, with annotations.
For this, I use subplots and I can plot each heatmap in its axes using the ax kwarg.
The issue is when I use xlim : it's applied to the heatmap, but not the annotation :
Here is the code :
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
values = np.random.random((7,24)) # create (7,24) shape array
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(30,10)) # create 2 columns for subplots
ax1 = sns.heatmap(values, annot=True, ax=ax1) # heatmap with annotation
ax1.set(xlim=(12,22)) # works fine with this line commented
# ax1.set_xlim(12,22)
# ax2 = sns.heatmap(values, annot=True, ax=ax2) # second heatmap
plt.show()
And it gets worse with a second heatmap, because the annotation from the second heatmap are ploted on the first heatmap.
How can I limit x axis to (12,22) while using annotation ?
- matplotlib 2.2.2
- seaborn 0.9.0
- python 3.6.5