I am plotting subplots of heatmap using seaborn with the following stripped down code. I get "AttributeError: 'numpy.ndarray' object has no attribute 'spines'" if I use nrows=2 and ncols=2, the plot works if either of nrows or ncols=1. How do I fix this?
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
fig, axes = plt.subplots(nrows=2, ncols=2)
sns.heatmap(Lpnl['19'],ax=axes[0])
plt.show()
Your axes
variable is a 2x2 numpy array. So when you do axes[0]
, it is giving you the first row. I assume you want axes[0, 0]
or axes.flat[0]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With