I wrote a python function for plotting a series of filled contours taking data from some columns of a dataset composed by a list of numpy arrays using the kdeplot
function of seaborn
. The code is the following:
import matplotlib.pyplot as plt
import seaborn as sns
def kdeplots_figure(dataset):
cols = int((len(dataset)-2)/2)
figure, axes = plt.subplots(1, cols, figsize=(15,6), sharey=True)
f = 2
for i in range (len(axes)):
sns.set_style("white")
axes[i].set_title(" Cluster {0}".format(i), fontsize = 16)
axes[i].set_ylabel('Y Axis', fontsize = 14)
axes[i].set_xlabel('X Axis', fontsize = 14)
axes[i].set_xlim([95,130])
axes[i].tick_params(labelsize=13)
sns.kdeplot(dataset[f],dataset[f+1],cmap="Blues_d",shade_lowest=True,ax=axes[i])
sns.kdeplot(dataset[f],dataset[f+1],cmap="Blues",shade_lowest=True,shade=True,ax=axes[i])
f = f+2
plt.show()
However, some of the contours differ in the space they sample in the x-y plane and when I plot them there is a white portion in the background of some of the graphs that I don't know how to fill. See below:
Both of the graphs should look like the one is located on the right side. I have tried setting up the background color using ax.set_facecolor
and taking the last color of the cmap palette with the help of this thread: Getting individual colors from a color map in matplotlib. However, the background color I get is slightly different. I also tried to use the clip argument of sns.kdeplot
with no luck.
How can I solve this? Let me know if you need additional information.