Skip to content

Instantly share code, notes, and snippets.

@amankharwal

amankharwal/IPL Secret

Created Sep 23, 2020
Embed
What would you like to do?
CSK_BATTING = pd.read_csv("IPL_2020_csk_mi_1216492_CSK_ShortData.csv", index_col=0)
CSK_BATTING = CSK_BATTING.drop(['text','preText','postText'], axis=1)
CSK_BATTING['bowlerToBatsman'] = CSK_BATTING['shortText'].str.split(',').str[0]
CSK_BATTING['bowler'] = CSK_BATTING['bowlerToBatsman'].str.split('to').str[0]
CSK_BATTING['batsman'] = CSK_BATTING['bowlerToBatsman'].str.split('to').str[1]
CSK_BATTING = CSK_BATTING.drop(['shortText'], axis=1)
MI_BATTING = pd.read_csv("IPL_2020_csk_mi_1216492_MI_ShortData.csv", index_col=0)
MI_BATTING = MI_BATTING.drop(['text','preText','postText'], axis=1)
MI_BATTING['bowlerToBatsman'] = MI_BATTING['shortText'].str.split(',').str[0]
MI_BATTING['bowler'] = MI_BATTING['bowlerToBatsman'].str.split('to').str[0]
MI_BATTING['batsman'] = MI_BATTING['bowlerToBatsman'].str.split('to').str[1]
MI_BATTING = MI_BATTING.drop(['shortText'], axis=1)
#print(CSK_BATTING)
CSK_HeatMap = pd.pivot_table(CSK_BATTING, index=['bowler'], columns='batsman', values='runs', aggfunc=np.sum)
MI_HeatMap = pd.pivot_table(MI_BATTING, index=['bowler'], columns='batsman', values='runs', aggfunc=np.sum)
#https://matplotlib.org/tutorials/colors/colormaps.html
f = plt.figure(figsize=(12,12))
gs = f.add_gridspec(2, 1)
with sns.axes_style("darkgrid"):
sns.set_context("notebook", font_scale=1.2, rc={"lines.linewidth": 3.5})
ax = f.add_subplot(gs[0, 0])
#g1 = sns.barplot(x='over', y='runs', data=MI_runs);
g1 = sns.heatmap(MI_HeatMap, annot=True, fmt="g", cmap='Blues')
g1.set_facecolor("#fdb913")
#g1.set_yticks(range(0,60,10))
#g1.set_ylim(0,60)
g1.axes.set_title("MI Batting Performance",fontsize=20)
g1.set_xlabel("Batsman",fontsize=18)
g1.set_ylabel("Bowler",fontsize=18)
g1.set_xticklabels(g1.get_xticklabels(), rotation=45)
g1.set_yticklabels(g1.get_yticklabels(), rotation=0)
with sns.axes_style("darkgrid"):
sns.set_context("notebook", font_scale=1.2, rc={"lines.linewidth": 3.5})
ax = f.add_subplot(gs[1, 0])
#g1 = sns.barplot(x='over', y='runs', data=MI_runs);
g1 = sns.heatmap(CSK_HeatMap, annot=True, fmt="g", cmap='Wistia')
g1.set_facecolor("#005ea0")
#g1.set_yticks(range(0,60,10))
#g1.set_ylim(0,60)
g1.axes.set_title("CSK Batting Performance",fontsize=20)
g1.set_xlabel("Batsman",fontsize=18)
g1.set_ylabel("Bowler",fontsize=18)
g1.set_xticklabels(g1.get_xticklabels(), rotation=45)
g1.set_yticklabels(g1.get_yticklabels(), rotation=0)
f.tight_layout(pad=3.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment