簡體   English   中英

繪制 Catplot 時額外的 Plot

[英]Extra Plot when drawing Catplot

使用以下代碼:

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()

我得到了以下 plot

在此處輸入圖像描述

為什么下面有一個額外的空白 plot? 如何不生成? (我需要ax為 catplot 提供額外的格式)

您可以使用以下技巧:在plt.show()之前關閉多余的圖形

plt.close(2)
plt.show()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM