S1: Describe the problem of a real user
S2: Find abstract operations and data types
S3: Design coding and interaction techniques
In [41]:
fig, axes= plt.subplots(2,1,figsize=(3, 6))
x = [25, 75]
l = ["have phone", "not have phone"]
axes[0].pie(x, labels=l)
axes[0].set_title("Teens have phone or not")
y = [10,30,60]
ly = ["t1","t2","t3"]
axes[1].pie(y, labels=ly)
axes[1].set_title("TEST")
fig.tight_layout()
fig.show()
In [1]:
#url = "http://boxofficemojo.com/movies/?page=weekly&id=cabininthewoods.htm"
In [17]:
ex1 = pd.read_csv("Day1Exe1.csv")
In [18]:
ex1.describe()
Out[18]:
In [86]:
tk = range(len(ex1.Weekly_Gross))
fig, axes= plt.subplots(3,1,figsize=(4, 8))
axes[0].set_title("The Cabin in the Woods")
axes[0].plot(arange(1,14),ex1.Rank,'x-')
axes[0].plot(arange(1,14),ones(13)*10,'g--')
axes[0].set_xlabel("weeks")
axes[0].set_ylabel("ranks")
axes[0].legend(["Rank", "Rank threshold"],loc=2)
axes[1].bar(tk, ex1.Weekly_Gross)
axes[1].set_xlabel("weeks")
axes[1].set_ylabel("Weekly_Gross(dollars)")
axes[1].legend(["weekly gross"])
axes[2].bar(tk, log(ex1.Weekly_Gross))
axes[2].set_xlabel("weeks")
axes[2].set_ylabel("log plot Weekly_Gross(dollars)")
axes[2].legend(["log plot of weekly gross"])
fig.tight_layout()
fig.show()
In [75]:
#linear fit months v.s. rank
z1 = np.polyfit(tk, ex1.Rank, 1)
z1
Out[75]:
In [92]:
#linear fit months v.s. log(weekly gross)
z2 = np.polyfit(tk, log(ex1.Weekly_Gross), 1)
z2
Out[92]:
In [2]:
%pylab inline
In [3]:
%qtconsole
In [23]:
import pandas as pd
In [24]:
data = pd.read_csv("milk-tea-coffee.tsv", sep="\t")
In [6]:
data.describe()
Out[6]:
In [20]:
fig, axes = plt.subplots(3,1,figsize=(9, 9))
axes[0].plot(data.Year, data.Milk, 'b-')
axes[0].set_xlabel("Years")
#axes[0].set_ylabel("Milk")
axes[0].set_ylabel("Gallons\nconsummd\nper\ncapita")
axes[0].set_title("Milk")
axes[0].grid(color='k', linestyle='-', linewidth=.5)
axes[1].plot(data.Year, data.Tea, 'xb')
axes[1].set_xlabel("Years")
axes[1].set_ylabel("Tea")
axes[2].plot(data.Year, data.Coffee, 'xk')
axes[2].set_xlabel("Years")
axes[2].set_ylabel("Coffee")
fig.tight_layout()
fig.show()
In [45]:
plot(ex1.Rank, ex1.Weekly_Gross)
show()
In [ ]:
## Interatciton
In [5]:
#e1: scatter
test = np.random.poisson(1,20)
In [10]:
fig, axes = plt.subplots()
axes.scatter(arange(20), test)
fig.show()
In [10]:
#ex2: boxplot, with error bar
In [12]:
#ex2: hist
In [ ]:
In [12]:
##??
In [13]:
#ex1:
x = np.random.randn(-1, 1) #Uniform
y = np.random.randn(-1, 1)
z = x.*y
#!!check plot(x, z)
In [ ]:
# Dependency:
y = sin(x) # correlate 0(globally)
In [12]:
In [13]:
In [14]:
In [1]:
%qtconsole
In [9]:
In [1]:
%pylab inline
In [3]:
%qtconsole
In [2]:
import pandas as pd
In [21]:
x = [5, 20, 10, 10]
fig, axes = plt.subplots()
axes.pie(x)
fig.show()
In [25]:
fig, axes = plt.subplots()
axes.pie(x, labels=["first","second","third","forth"],colors = ('r','g','b','y'), shadow=True)
fig.show()
In [24]:
# fig, axes = plt.subplots(2, 1, figsize=(9, 6))
In [16]:
x = np.random.randint(1, high=5, size=1000)
In [17]:
plot(x)
Out[17]:
In [43]:
from pylab import *
from scipy import *
# reading the data from a csv file
durl = 'http://datasets.flowingdata.com/crimeRatesByState2005.csv'
rdata = genfromtxt(durl,dtype='S8,f,f,f,f,f,f,f,i',delimiter=',')
rdata[0] = zeros(8) # cutting the label's titles
rdata[1] = zeros(8) # cutting the global statistics
x = []
y = []
color = []
area = []
for data in rdata:
x.append(data[1]) # murder
y.append(data[5]) # burglary
color.append(data[6]) # larceny_theft
area.append(sqrt(data[8])) # population
# plotting the first eigth letters of the state's name
text(data[1], data[5],data[0],size=11,horizontalalignment='center')
# making the scatter plot
sct = scatter(x, y, c=color, s=area, linewidths=2, edgecolor='w')
sct.set_alpha(0.75)
axis([0,11,200,1280])
xlabel('Murders per 100,000 population')
ylabel('Burglaries per 100,000 population')
show()
In [45]:
dupd = pd.read_csv("http://datasets.flowingdata.com/crimeRatesByState2005.csv")
In [50]:
#dupd.irow
In [9]:
pwd
Out[9]:
In [ ]: