Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

subplot error in Matplotlib using seaborn

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()
like image 668
user3404344 Avatar asked Jun 03 '16 01:06

user3404344


1 Answers

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].

like image 52
mwaskom Avatar answered Oct 30 '22 18:10

mwaskom