-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbar.py
More file actions
110 lines (46 loc) · 1.44 KB
/
bar.py
File metadata and controls
110 lines (46 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#출처: https://rfriend.tistory.com/411 [R, Python 분석과 프로그래밍의 친구 (by R Friend)]
# importing packages
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
plt.rcParams['figure.figsize'] = [10, 6]
# Loading 'tips' dataset from seaborn
tips = sns.load_dataset('tips')
tips.shape
tips.head()
# Summary Statistics
tips_sum_by_day = tips.groupby('day').tip.sum()
tips_sum_by_day
label = ['Thur', 'Fri', 'Sat', 'Sun']
index = np.arange(len(label))
# Basic Bar Chart
plt.bar(index, tips_sum_by_day)
plt.title('Sum of Tips by Day', fontsize=20)
plt.xlabel('Day', fontsize=18)
plt.ylabel('Sum of Tips', fontsize=18)
plt.xticks(index, label, fontsize=15)
plt.show()
# bar color, transparency
plt.bar(label, tips_sum_by_day,
color='red', # color
alpha=0.5) # transparency
plt.show()
# bar width, align
plt.bar(label, tips_sum_by_day,
width=0.5, # default: 0.8
align='edge') # default: 'center'
plt.show()
# X tick labels rotation
plt.bar(index, tips_sum_by_day)
plt.xlabel('Day', fontsize=18)
plt.xticks(index, label, fontsize=15,
rotation=90) # when X tick labels are long
plt.show()
# Horizontal Bar Chart
plt.barh(index, tips_sum_by_day)
plt.title('Sum of Tips by Day', fontsize=18)
plt.ylabel('Day', fontsize=15)
plt.xlabel('Sum of Tips', fontsize=15)
plt.yticks(index, label, fontsize=13, rotation=0)
plt.show()