Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions q01_plot_deliveries_by_team/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q01_plot_deliveries_by_team/build.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -7,3 +8,24 @@


# Solution

def plot_deliveries_by_team():
x=ipl_df.groupby('batting_team').delivery.count()
plt.bar(x.index,x.values)
plt.show()

plt.bar([1,2,3],[1,4,9])
plt.show()
x=ipl_df.groupby('batting_team').delivery.count()
type(x)
plt.bar(x,height=2)
plt.show()
x
x[0]
x[1]
x.index
x.values
u=x.index
np.array(u)


12 changes: 12 additions & 0 deletions q02_plot_matches_by_team/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q02_plot_matches_by_team/build.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -6,3 +7,14 @@


# Solution
def plot_matches_by_teams():
x=ipl_df.groupby('batting_team').match_code.nunique()
plt.bar(x.index, x.values)
plt.show()
x=ipl_df.groupby('batting_team').match_code.nunique()
x.index
x.values
plt.bar(x.index,x.values)
plt.show()


34 changes: 34 additions & 0 deletions q03_plot_innings_runs_histogram/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
# %load q03_plot_innings_runs_histogram/build.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

plt.switch_backend('agg')
ipl_df = pd.read_csv('data/ipl_dataset.csv', index_col=None)


# Solution
def plot_innigs_runs_histogram():
x=ipl_df[ipl_df['toss_decision']=='bat']['total']
y=ipl_df[ipl_df['toss_decision']=='field']['total']
fig, ax = plt.subplots(1,2)
ax[0].hist(x, bins=10, alpha = 0.5, color = 'r')
ax[1].hist(y, bins=10, alpha = 0.5, color = 'g')
plt.show()

x=ipl_df[ipl_df['toss_decision']=='bat']['total']
y=ipl_df[ipl_df['toss_decision']=='field']['total']
plt.subplots(2,1)
plt.hist(y,bins=10)


# An 'interface' to matplotlib.axes.Axes.hist() method
n, bins, patches = plt.hist(x=x, bins='auto', color='#0504aa',
alpha=0.7, rwidth=0.85)
plt.grid(axis='y', alpha=0.75)
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('My Very Own Histogram')
plt.text(23, 45, r'$\mu=15, b=3$')
maxfreq = n.max()
# Set a clean upper y-axis limit.
plt.ylim(ymax=np.ceil(maxfreq / 10) * 10 if maxfreq % 10 else maxfreq + 10)
fig, ax = plt.subplots(1,2)
ax[0].hist(x, bins=10, alpha = 0.5, color = 'r')
ax[1].hist(y, bins=10, alpha = 0.5, color = 'g')
plt.show()
plot_innigs_runs_histogram()


15 changes: 15 additions & 0 deletions q04_plot_runs_by_balls/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q04_plot_runs_by_balls/build.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -6,3 +7,17 @@


# Solution
def plot_runs_by_balls():
plt.scatter(ipl_df['runs'],ipl_df.index)
plt.show()


plt.scatter(ipl_df['runs'],ipl_df.index)
plt.show()
fig, ax = plt.subplots(1,2)
ax[0].hist(x, bins=10, alpha = 0.5, color = 'r')
ax[1].hist(y, bins=10, alpha = 0.5, color = 'g')
plt.show()
plot_runs_by_balls()