<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
Step1:  Scope
1. Representation - 2D, 3D plots
2. Provide idioms
-- "Business graphics" line, bar, scatter plots
-- "Statistics plots" whisker
-- "Higher dimensioned data" - heatmap
3. In-class problem solving for a task
Step2:  Visualization in Python
There are many python packages for visualization. We'll start with the most popular package, matplotlib. And, we'll use the trip data.
Step3:  Now let's consider the popularity of the stations.
Step4:  Our initial task is comparison - which stations are most popular. A bar plot seems appropriate.
Step5:  Now let's plot the to counts
Step6:  We want if there is a general movement of bikes from one station to another. That is, are from and to counts out of balance. This is a comparison task. One approach is to combine the two bar plots in the same figure.
Step7:  But this is deceptive since the two plots have different x-axis.
Step8:  But this is awkward since it's difficult to find a specific station. Prefer to sort.
We'd like to compare this with the two stations. So, we need to order the x-axis.
Step9:  To find the imbalance, compare the difference between "from" and "to"
Step10:  We can make this readable by only looking at stations with large outflows, either positive or negative.
<ASSISTANT_TASK:>
Python Code:
def mm(s_conc, vmax, km):
    
    :param np.array s_conc: substrate concentrations
    :param float vmax: maximum reaction rate
    :param float km: half substrate concentration
    :return np.array: reaction rates
    
    result = vmax*s_conc/(s_conc+km)
    return result
s_conc = np.array([m+0.1 for m in range(100)])
plt.plot(s_conc,mm(s_conc, 4, .4), 'b.-')
s_conc = np.array([m+0.1 for m in range(100)])
params = [(5,0.5), (5, 20), (10, 0.5), (15, 20)]
ymax = max([x for (x,y) in params])
nplots = len(params)
fig = plt.figure()                                                                                                                                                        
yticks = np.arange(0, ymax)                                                                                             
cur = 0
for (vmax, km) in params:
    cur += 1
    ax = fig.add_subplot(nplots, 1, cur)
    ax.axis([0, len(s_conc), 0, ymax])
    ax.set_yticks([0, ymax])
    ax.set_yticklabels([0, ymax])
    plt.plot(s_conc, mm(s_conc, vmax, km), 'b.-')
plt.show()
# Parameter plot
km = [y for (x,y) in params]
vmax = [x for (x,y) in params]
plt.axis([0, max(km)+2, 0, max(vmax)+ 2])
plt.xlabel('K_M')
plt.ylabel('V_MAX')
plt.plot(km, vmax, 'bo ')
Explanation: Scope
1. Representation - 2D, 3D plots
2. Provide idioms
-- "Business graphics" line, bar, scatter plots
-- "Statistics plots" whisker
-- "Higher dimensioned data" - heatmap
3. In-class problem solving for a task
End of explanation
import pandas as pd
import matplotlib.pyplot as plt
# The following ensures that the plots are in the notebook
%inline matplotlib
# We'll also use capabilities in numpy
import numpy as np
df = pd.read_csv("2015_trip_data.csv")
df.head()
Explanation: Visualization in Python
There are many python packages for visualization. We'll start with the most popular package, matplotlib. And, we'll use the trip data.
End of explanation
from_counts = pd.value_counts(df.from_station_id)
to_counts = pd.value_counts(df.to_station_id)
Explanation: Now let's consider the popularity of the stations.
End of explanation
from_counts.plot.bar()
Explanation: Our initial task is comparison - which stations are most popular. A bar plot seems appropriate.
End of explanation
to_counts.plot.bar()
Explanation: Now let's plot the to counts
End of explanation
plt.subplot(3,1,1)
from_counts.plot.bar()
plt.subplot(3,1,3)
to_counts.plot.bar()
# Note the use of an empty second plot to provide space between the plots
Explanation: We want if there is a general movement of bikes from one station to another. That is, are from and to counts out of balance. This is a comparison task. One approach is to combine the two bar plots in the same figure.
End of explanation
count_list = [to_counts[x] for x in from_counts.index]
ordered_to_counts = pd.Series(count_list, index=from_counts.index)
plt.subplot(3,1,1)
from_counts.plot.bar()
plt.subplot(3,1,3)
ordered_to_counts.plot.bar()
Explanation: But this is deceptive since the two plots have different x-axis.
End of explanation
df_counts = pd.DataFrame({'from': from_counts.values, 'to': ordered_to_counts.values}, index=from_counts.index)
df_counts.head()
df_counts.sort_index(inplace=True)  # Modifies the calling dataframe
df_counts.head()
Explanation: But this is awkward since it's difficult to find a specific station. Prefer to sort.
We'd like to compare this with the two stations. So, we need to order the x-axis.
End of explanation
df_outflow = pd.DataFrame({'outflow':df_counts.to - df_counts['from']}, index=df_counts.index)
df_outflow.plot.bar(legend=False)
Explanation: To find the imbalance, compare the difference between "from" and "to"
End of explanation
min_outflow = 500
sel = abs(df_outflow.outflow) > min_outflow
df_outflow_small = df_outflow[sel]
df_outflow_small.plot.bar(legend=False)
Explanation: We can make this readable by only looking at stations with large outflows, either positive or negative.
End of explanation
<END_TASK>