In [41]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import mpld3
mpld3.enable_notebook()
In [42]:
fig, ax = plt.subplots(subplot_kw=dict(axisbg='#EEEEEE'), figsize=(10,5))
ax.grid(color='white', linestyle='solid')
N = 50
scatter = ax.scatter(np.random.normal(size=N),
np.random.normal(size=N),
c=np.random.random(size=N),
s = 1000 * np.random.random(size=N),
alpha=0.3,
cmap=plt.cm.jet)
ax.set_title("D3 Scatter Plot", size=18);
In [43]:
import mpld3
from mpld3 import plugins
from mpld3.utils import get_id
import collections
N_paths = 5
N_steps = 100
x = np.linspace(0, 10, 100)
y = 0.1 * (np.random.random((N_paths, N_steps)) - 0.5)
y = y.cumsum(1)
fig, ax = plt.subplots()
labels = ["a", "b", "c", "d", "e"]
line_collections = ax.plot(x, y.T, lw=4, alpha=0.2)
mpld3.display()
Out[43]:
In [5]:
from __future__ import print_function
import datetime
import matplotlib.pyplot as plt
from matplotlib.dates import MONDAY
from matplotlib.finance import quotes_historical_yahoo
from matplotlib.dates import MonthLocator, WeekdayLocator, DateFormatter
date1 = datetime.date( 2002, 1, 5 )
date2 = datetime.date( 2003, 12, 1 )
# every monday
mondays = WeekdayLocator(MONDAY)
# every 3rd month
months = MonthLocator(range(1,13), bymonthday=1, interval=3)
monthsFmt = DateFormatter("%b '%y")
quotes = quotes_historical_yahoo('INTC', date1, date2)
if len(quotes) == 0:
print ('Found no quotes')
raise SystemExit
dates = [q[0] for q in quotes]
opens = [q[1] for q in quotes]
fig, ax = plt.subplots()
ax.plot_date(dates, opens, '-')
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(monthsFmt)
ax.xaxis.set_minor_locator(mondays)
ax.autoscale_view()
#ax.xaxis.grid(False, 'major')
#ax.xaxis.grid(True, 'minor')
ax.grid(True)
fig.autofmt_xdate()
plt.show()
In [12]:
log_file = 'http://sprg.ssl.berkeley.edu/~brentm/textlog.dat'
import urllib2
from datetime import datetime
In [48]:
response = urllib2.urlopen(log_file)
times = []
temp = []
for line in response:
date = line.split('--')[0]
data = line.split('--')[1]
times.append(datetime.strptime(date[0:-1], '%B %d %Y %H:%M:%S'))
if data[1] == 'C':
temp.append(float(data[4:8]))
else:
temp.append(np.nan)
response.close()
In [49]:
len(times)
Out[49]:
In [50]:
times[0]
Out[50]:
In [51]:
temp[100]
Out[51]:
In [56]:
fig, ax = plt.subplots(figsize=(10,5))
ax.plot_date(times[::10], temp[::10], '-')
mpld3.display()
Out[56]:
In [ ]: