本文介绍了绘制猫图时的额外图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用以下代码:
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()
我得到了以下情节
为什么下面有一个额外的空白图?如何不产生那个?(我需要 ax
为猫图提供额外的格式)
Why there is an extra blank plot below? How to not generate that?(I need the ax
to provide extra formatting for catplot)
推荐答案
你可以使用以下技巧:关闭 plt.show()
You can use the following trick : Close the extra figure before plt.show()
plt.close(2)
plt.show()
这篇关于绘制猫图时的额外图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!