Pandas 그래프 두번 중복되는 이유?

조회수 326회

파이썬 초보입니다. 타이타닉 문제를 갖고 그래프를 그리던 중 뜻대로 되지 않아 질문 남기게 되었습니다.

일단 데이터 이름을 이렇게 정했고, 아래에 그래프 코드를 적었습니다.

제가 그려야하는 그래프는 x=나이 y=빈도수 로 생존한 사람(초록색)과 죽은 사람(빨간색)의 분포를 히스토그램으로 나타내는 것입니다.

1x2 로 두개의 그래프에 남자 분포 따로, 여자 분포 따로 적어야 하는데 결과값이 2x2로 같은 값이 중복되어 한번 더 나옵니다. 혹시 어느 부분이 틀렸을까요?

df_Mr_survived=sqldf("SELECT Age, Fare FROM df_titanic WHERE Title = 'Mr.' AND Survived = 1 ")
df_Mr_died=sqldf("SELECT Age, Fare FROM df_titanic WHERE Title = 'Mr.' AND Survived = 0")
df_Mrs_survived=sqldf("SELECT Age, Fare FROM df_titanic WHERE Title = 'Mrs.' AND Survived = 1")
df_Mrs_died=sqldf("SELECT Age, Fare FROM df_titanic WHERE Title = 'Mrs.' AND Survived = 0")
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use("ggplot")

fig, (ax0, ax1)=plt.subplots(nrows=1, ncols=2, figsize=(12, 6))

df_Mr_survived['Age'].plot(kind="hist", color='g', alpha=0.5, ax=ax0, label = 'Survived')
df_Mr_died['Age'].plot(kind="hist",color='r',alpha=0.2, ax=ax0, label = 'Died')
ax0.set(title="Distribution of Age for Mr.", xlabel="Age", ylabel="Frequency")
ax0.set_xlim([0, 83])
ax0.legend(loc='upper right')

df_Mrs_survived['Age'].plot(kind="hist", color='g', alpha=0.2, ax=ax1, label = 'Survived')
df_Mrs_died['Age'].plot(kind="hist",color='r',alpha=0.5, ax=ax1, label = 'Died')
ax1.set(title="Distribution of Age for Mrs.", xlabel="Age", ylabel="Frequency")
ax1.set_xlim([0, 65])
ax1.legend(loc='upper right')
fig 

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)