<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Chapter 4
Data Visualization
Step1:  4.1 Introduction
Case Study
Step2:  4.2 Basic Visualizations
4.2.1 Scatterplots
Independent and Dependent Variables
Step3:  4.2.1.1 Labeling Data Points
Step4:  4.2.1.2 Points and Lines
Step5:  4.2.2 Visualizing Aggregate Values with Bar plots and Pie charts
4.2.2.1 Group Data by a Variable
Step6:  4.2.2.2 Bar Plots
Step7:  4.2.3 Common Plotting Tasks
4.2.3.1 Multiple Plots
Step8:  4.4 Interactive Visualizations Using Bokeh
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
from matplotlib import pylab as plt
plt.rcParams['figure.figsize'] = (15.0, 10.0)
import pandas as pd
import seaborn as sns
Explanation: Chapter 4
Data Visualization
End of explanation
data = pd.read_csv("978-3-319-12065-2/chapter-4/teams.csv")
data.head()
Explanation: 4.1 Introduction
Case Study: 2012 Major League Baseball Season
End of explanation
data.plot(kind='scatter',x="payroll",y="wins")
sns.regplot("payroll","wins",data,fit_reg=False)
Explanation: 4.2 Basic Visualizations
4.2.1 Scatterplots
Independent and Dependent Variables
End of explanation
def label_point_orig(x, y, val, ax):
    a = pd.concat({'x': x, 'y': y, 'val': val}, axis=1)
    for i, point in a.iterrows():
        ax.text(point['x'], point['y'], str(point['val']))
ax = data.plot(kind='scatter',x="payroll",y="wins")
label_point_orig(data.payroll,data.wins,data.code,ax)
ax1 = sns.regplot("payroll","wins",data,fit_reg=False)
label_point_orig(data.payroll,data.wins,data.code,ax1)
Explanation: 4.2.1.1 Labeling Data Points
End of explanation
data_al = data[data.league == "AL"]
data_nl = data[data.league == "NL"]
fig, ax = plt.subplots()
ax.plot(data_al.payroll, data_al.wins, marker='o',linestyle='',label="AL")
ax.plot(data_nl.payroll, data_nl.wins, marker='s',linestyle='',label="NL")
ax.legend()
ax.set_xlabel("payroll")
ax.set_ylabel("wins")
data_groups = data.groupby('league')
markers = ["o","s"]
mindx = 0
fig, ax = plt.subplots()
for name, group in data_groups:
    ax.plot(group.payroll, group.wins, marker=markers[mindx], linestyle='', ms=12, label=name)
    mindx += 1
ax.legend()
ax.set_xlabel("payroll")
ax.set_ylabel("wins")
data_gf_al = data[data.pct >= 0.5 ]
data_gf_nl = data[data.pct <= 0.5]
fig, ax = plt.subplots()
ax.plot(data_gf_al.payroll,data_gf_al.wins,marker='o',linestyle='')
ax.plot(data_gf_nl.payroll,data_gf_nl.wins,marker='s',linestyle='')
ax.plot([data.payroll.min(),data.payroll.max()],[81,81])
data_groups = data.groupby('league')
markers = ["o","^"]
mindx = 0
fig, ax = plt.subplots()
for name, group in data_groups:
    ax.plot(group.payroll, group.wins, marker=markers[mindx], linestyle='', ms=12, label=name)
    mindx += 1
ax.legend()
ax.set_xlabel("payroll")
ax.set_ylabel("wins")
Explanation: 4.2.1.2 Points and Lines
End of explanation
data[data.league == "NL"].payroll.sum()
data.groupby("league").payroll.sum()
data.groupby(["league","division"]).payroll.sum()
data.groupby("league").payroll.sum().plot(kind='bar')
Explanation: 4.2.2 Visualizing Aggregate Values with Bar plots and Pie charts
4.2.2.1 Group Data by a Variable
End of explanation
data.groupby(["league","division"]).payroll.sum().plot(kind='bar',stacked=True)
data.groupby(["league","division"]).payroll.sum().unstack("division").plot(kind='bar',stacked=True)
data.groupby(["league","division"]).payroll.sum().unstack("division").plot(kind='bar')
data.groupby(["league"]).payroll.sum().plot(kind='pie')
data.groupby(["league","division"]).payroll.sum().plot(kind='pie')
Explanation: 4.2.2.2 Bar Plots
End of explanation
data_al = data[data.league == "AL"]
data_nl = data[data.league == "NL"]
fig, ax = plt.subplots(2)
ax[0].plot(data_al.payroll, data_al.wins, marker='o', linestyle='', ms=12, label="AL")
ax[1].plot(data_nl.payroll, data_nl.wins, marker='o', linestyle='', ms=12, label="NL")
Explanation: 4.2.3 Common Plotting Tasks
4.2.3.1 Multiple Plots
End of explanation
from bokeh.sampledata.iris import flowers
from bokeh.plotting import figure, show, output_file,output_notebook
output_notebook()
colormap = {'AL': 'red', 'NL': 'green'}
data['color'] = data['league'].map(lambda x: colormap[x])
p = figure(title = "Payroll vs Wins")
p.xaxis.axis_label = 'Wins'
p.yaxis.axis_label = 'Payroll'
p.circle(data.payroll,data.wins,color=data["color"],size=10)
show(p)
Explanation: 4.4 Interactive Visualizations Using Bokeh
End of explanation
<END_TASK>