In [1]:
y = randn(1000)
plot(y)
Out[1]:
In [116]:
cd data/citydata/
In [117]:
ls
In [11]:
import pandas as pd
In [118]:
filename = 'worldcitiespop.txt'
In [119]:
data = pd.read_csv(filename)
In [15]:
plot(data.Longitude, data.Latitude, ',')
Out[15]:
In [120]:
data.describe()
Out[120]:
In [19]:
data.head()
Out[19]:
In [27]:
data[data.AccentCity=='Dikili']
Out[27]:
In [28]:
cd fbdata
In [29]:
pwd
Out[29]:
In [30]:
import networkx as nx
In [31]:
g = nx.read_edgelist('0.edges')
In [32]:
hist(g.degree().values(), bins=20)
Out[32]:
In [33]:
x = linspace(-10, 10)
y = sin(x)
In [37]:
plot(x, sin(x), '-r', label='sinus')
plot(x, cos(x), '--g', label='cosinus')
xticks([-10, 0, 10])
yticks([-1, 0, 1])
ylim(-2, 2)
legend()
grid()
In [40]:
plot(randn(1000, 2))
Out[40]:
In [41]:
line = _[0]
In [44]:
line.set_color('r') # doesnt work in notebook
In [45]:
x = linspace(0, 2*pi, 1000)
y = 1 + 2*cos(5*x)
subplot(1,2,1)
plot(x,y)
subplot(1,2,2, polar=True)
polar(x,y)
Out[45]:
images:
In [47]:
import urllib2
In [101]:
png = urllib2.urlopen('http://ipython.rossant.net/squirrel.png')
In [102]:
im = imread(png)
In [103]:
im.shape
Out[103]:
In [51]:
from PIL import Image
In [52]:
img = Image.fromarray((im*255).astype('uint8'))
In [104]:
imshow(im)
Out[104]:
In [54]:
imshow(array(img.rotate(45.)))
Out[54]:
Color quantization:
In [55]:
from scipy.cluster.vq import *
In [105]:
M = im[:,:,0].ravel()
In [106]:
centroids, _ = kmeans(M, 4)
In [58]:
qnt, _ = vq(M, centroids)
In [59]:
clustered = centroids[reshape(qnt, (300, 300))]
In [61]:
mymap = matplotlib.colors.ListedColormap([(0, .2, .3), (.85, .1, .13), (.44, .6, .6), (1., .9, .65)])
In [62]:
imshow(clustered, cmap=mymap)
Out[62]:
In [68]:
imsave('squirrelama.png', clustered, cmap=mymap)
Multichannel quantization:
In [111]:
Mred = transpose(im[:,:,0].ravel())
Mgreen = im[:,:,1].ravel().T
Mblue = im[:,:,2].ravel().T
In [110]:
Mred.shape
Out[110]:
In [88]:
BigM = concatenate((Mred, Mgreen, Mblue), axis=1)
In [76]:
Mcentoids, _ = kmeans(M, 5)
In [77]:
Mqnt, _ = vq(BigM, Mcentoids)
In [79]:
Mclustered = Mcentoids[reshape(Mqnt, (300, 300, 3))]
In [81]:
Mqnt.shape
Out[81]:
In [82]:
Mcentoids.shape
Out[82]:
In [89]:
BigM.shape
Out[89]:
In [121]:
locations = data[['Longitude','Latitude']].as_matrix()
In [122]:
population = data.Population
In [124]:
from mpl_toolkits.basemap import Basemap
In [125]:
from mpl_toolkits.mplot3d import Axes3D
In [127]:
X = linspace(-5, 5)
Y = X
X, Y = meshgrid(X, Y)
R = sqrt(X**2 + Y**2)
Z = sin(R)
In [130]:
ax = gca(projection='3d')
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=mpl.cm.coolwarm, linewidth =0)
In [1]:
# gui qt (this section works in console mode, but crashes the kernel in the notebook)
In [2]:
from PySide import QtGui
In [3]:
class SideApp(QtGui.QWidget):
def __init__(self):
super(SideApp, self).__init__()
self.button = QtGui.QPushButton('Click me', self)
self.button.clicked.connect(self.clicked)
vbox = QtGui.QVBoxLayout()
vbox.addWidget(self.button)
self.setLayout(vbox)
self.show()
def clicked(self):
msg = QtGui.QMessageBox(self)
msg.setText('Hello world!')
msg.show()
In [1]:
# window = SideApp()
In [ ]: