import seaborn as sns
tips = sns.load_dataset('tips')
print(tips.head())
print(type(tips))
%matplotlib notebook
import matplotlib.pyplot as plt
fig = plt.figure()
axes1 = fig.add_subplot(1, 1, 1)
axes1.hist(tips['total_bill'], bins=10)
axes1.set_title('Histogram of Total Bill')
axes1.set_xlabel('Frequency')
axes1.set_ylabel('Total Bill')
scatter_plot = plt.figure()
axes1 = scatter_plot.add_subplot(1, 1, 1)
axes1.scatter(tips['total_bill'], tips['tip'])
axes1.set_title('Scatterplot of Total Bill vs Tip')
axes1.set_xlabel('Total Bill')
axes1.set_ylabel('Tip')
boxplot = plt.figure()
axes1 = boxplot.add_subplot(1, 1, 1)
axes1.boxplot([tips[tips['sex'] == 'Female']['tip'],
tips[tips['sex'] == 'Male']['tip']],
labels=['Female', 'Male'])
axes1.set_xlabel('Sex')
axes1.set_ylabel('Tip')
axes1.set_title('Boxplot of Tips by Sex')
def recode_sex(sex):
if sex == 'Female':
return 0
else:
return 1
tips['sex_color'] = tips['sex'].apply(recode_sex)
scatter_plot = plt.figure()
axes1 = scatter_plot.add_subplot(1, 1, 1)
axes1.scatter(
x = tips['total_bill'],
y = tips['tip'],
s = tips['size'] * 10, # 점의 크기
c = tips['sex_color'], # 점의 색상
alpha = 0.5
)
'Development > Python' 카테고리의 다른 글
[pandas] DO IT 데이터분석을 위한 판다스 입문 (Chart Documentation) (0) | 2019.10.04 |
---|---|
[pandas] DO IT 데이터분석을 위한 판다스 입문 (그래프3) (0) | 2019.10.04 |
[pandas] DO IT 데이터분석을 위한 판다스 입문 (그래프) (0) | 2019.10.03 |
[pandas] DO IT 데이터분석을 위한 판다스 입문 (데이터 저장) (0) | 2019.10.02 |
[pandas] DO IT 데이터분석을 위한 판다스 입문 (DataFrame2) (0) | 2019.10.02 |