2016-12-20 4 views
0

마지막 서브 플롯에 문제가 있습니다. 마지막 교차 분석 플롯 자체가 나타나고 하위 플롯에는 처음 2 개의 서브 도표가 있지만 세 번째 서브 도표는 비어 있으며 데이터가 없습니다. 어떻게 당신은 음모를 꾸미고 팬더를 알려줄 필요가 나는 3 개 그래프는 하나의 그림에 와서 있도록 그래프를 그리고 그들은 그들에게 동일한 Y 축 또는 '주파수'서브 플로트 3 그래프 하나의 그림

import numpy as np 
import pandas as pd 
import statsmodels.api as sm 
import matplotlib.pyplot as plt 
from patsy import dmatrices 
from sklearn.linear_model import LogisticRegression 
from sklearn.cross_validation import train_test_split 
from sklearn import metrics 
from sklearn.cross_validation import cross_val_score 

#Data Exploration 
data = sm.datasets.fair.load_pandas().data 
data['affair'] = np.where(data['affairs'] > 0 , 1,0) 
print(data) 
print(data.groupby('affair').mean()) 
print(data.groupby('rate_marriage').mean()) 

plt.subplot(331) 
data['educ'].hist() 
plt.title('Histogram of Education') 
plt.xlabel('Education Level') 
plt.ylabel('Frequency') 
plt.subplot(332) 
data['rate_marriage'].hist() 
plt.title('Histogram of Marriage Rating') 
plt.xlabel('Marriage Rating') 
plt.ylabel('Frequency') 
plt.subplot(333) 
pd.crosstab(data['rate_marriage'], data['affair'].astype(bool)).plot(kind='bar') 
plt.title('Marriage Rating distribution by affair Status') 
plt.xlabel('Marriage Rating') 
plt.ylabel('Frequency') 
plt.show() 

This is the subplot with the blank data

This is what should be in the subplot

답변

1

를 공유 할 수 있습니다 함수를 사용하여 데이터를 플롯 할 수 있습니다. ax 키워드를 통해이 작업을 수행 할 수 있습니다.

ax= plt.subplot(333) 
pd.crosstab(data['rate_marriage'], data['affair'].astype(bool)).plot(kind='bar', ax=ax) 
관련 문제