简体   繁体   中英

Extra Plot when drawing Catplot

Using the following code:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
df1 = pd.DataFrame( {'category': {0: 'Cat', 1: 'Cat', 2: 'Cat', 3: 'Cat', 4: 'Dog', 5: 'Dog', 6: 'Dog', 7: 'Dog', 8: 'Dog', 9: 'Dog', 10: 'Dog', 11: 'Dog', 12: 'Dog', 13: 'Dog', 14: 'Dog', 15: 'Dog', 16: 'Dog', 17: 'Dog', 18: 'Dog', 19: 'Dog'}, 'shape': {0: 'Small', 1: 'Small', 2: 'Small', 3: 'Small', 4: 'Small', 5: 'Small', 6: 'Small', 7: 'Medium', 8: 'Medium', 9: 'Large', 10: 'Small', 11: 'Small', 12: 'Small', 13: 'Small', 14: 'Small', 15: 'Small', 16: 'Small', 17: 'Small', 18: 'Small', 19: 'Small'}} )
plt.figure(figsize=(5,5),facecolor='#ffffff')
ax = plt.axes(facecolor='#ffffff')
plt.xticks(rotation=25)
sns.catplot(x='shape', hue='category', kind ='count', data = df1, height=5, aspect=1,ax=ax)
plt.xlabel('Diamond Shape')
plt.show()

I got the following plot

在此处输入图像描述

Why there is an extra blank plot below? How to not generate that? (I need the ax to provide extra formatting for catplot)

You can use the following trick: Close the extra figure before plt.show()

plt.close(2)
plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM