-
Notifications
You must be signed in to change notification settings - Fork 0
/
BarChart_plt.py
108 lines (87 loc) · 3.29 KB
/
BarChart_plt.py
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
100
101
102
103
104
105
106
107
# coding: utf-8
# In[2]:
def mul_barchart(df):
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import mpl_toolkits.mplot3d.art3d as art3d
from numpy import pi, arange, linspace, sin
min_year = int(df['Year'].dropna().min())
max_year = int(df['Year'].dropna().max())
year_range = range(min_year,max_year+1)
year_saleNA = []
year_saleEU = []
year_saleJP = []
year_saleO = []
year_list = []
for year in year_range:
year_saleNA.append(df[df['Year'] == year].dropna()['NA_Sales'].sum())
year_saleEU.append(df[df['Year'] == year].dropna()['EU_Sales'].sum())
year_saleJP.append(df[df['Year'] == year].dropna()['JP_Sales'].sum())
year_saleO.append(df[df['Year'] == year].dropna()['Other_Sales'].sum())
year_list.append(year)
x = year_list
plt.figure(figsize=(20,10))
plt.fill_between(x,year_saleNA,alpha=0.4,step="pre",label = "North America")
plt.fill_between(x,year_saleEU,alpha=0.4,step="pre",label = "Europ")
plt.fill_between(x,year_saleJP,alpha=0.4,step="pre",label = "Japan")
plt.fill_between(x,year_saleO,alpha=0.4,step="pre", label = "Other")
plt.plot(x,year_saleNA,drawstyle="steps")
plt.plot(x,year_saleEU,drawstyle="steps")
plt.plot(x,year_saleJP,drawstyle="steps")
plt.plot(x,year_saleO,drawstyle="steps")
plt.legend(loc='upper right')
plt.title('Total Sales on different region',fontsize=15 )
plt.ylabel('Total Sales in millions',fontsize=15)
plt.xlabel('Year',fontsize=15)
plt.show()
# In[9]:
def Platf (c):
if c['Platform'] in PlayStation:
return 'PlayStation'
elif c['Platform'] in Nintendo:
return 'Nintendo'
elif c['Platform'] in Microsoft:
return 'Microsoft'
elif c['Platform'] in Other:
return 'Other'
else:
return 'Outflit'
# In[10]:
def bar_grid(df,x):
import numpy as np
import colorsys
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from collections import Counter
get_ipython().run_line_magic('matplotlib', 'inline')
sns.set_style("darkgrid")
ax=df.set_index('Name')[['North America', 'Europe', 'Japan', 'Other']].plot(kind='barh',
figsize=(18, 12), stacked=True)
plt.title(x, fontsize=26)
plt.xlabel("Total Sales(Million$)", fontsize=26)
plt.ylabel("Name", fontsize=26)
plt.yticks(fontsize=22)
plt.xticks(fontsize=22)
plt.legend(fontsize=22)
# In[11]:
def comp_bar(before,after,xx):
import numpy as np
import colorsys
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from collections import Counter
get_ipython().run_line_magic('matplotlib', 'inline')
combined=pd.merge(before, after, on="Platf")
combined=combined.rename(index=str, columns={"Global_Sales_x": "2005-2010 Sales", "Global_Sales_y": "2011-2016 Sales"})
sns.set_style("darkgrid")
combined.set_index('Platf')[['2005-2010 Sales', '2011-2016 Sales']].plot(kind='bar',figsize=(18, 12))
plt.xticks(rotation = 0)
plt.title(xx, fontsize=26, y=1.01)
plt.xlabel("Platform groups", fontsize=26)
plt.ylabel("Total Sales in [Million $] ", fontsize=26)
plt.yticks(fontsize = 24 )
plt.xticks(fontsize = 24 )
#ax = plt.gca()
plt.legend(fontsize=20);