This repository has been archived by the owner on Aug 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
/
scatter_chart_examples.py
57 lines (47 loc) · 1.97 KB
/
scatter_chart_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
"""
Vincent Scatter Examples
"""
#Build a Line Chart from scratch
from vincent import *
import pandas.io.data as web
all_data = {}
for ticker in ['AAPL', 'GOOG', 'IBM', 'YHOO', 'MSFT']:
all_data[ticker] = web.get_data_yahoo(ticker, '1/1/2010', '1/1/2013')
price = pd.DataFrame({tic: data['Adj Close']
for tic, data in all_data.iteritems()})
#Note that we're using timeseries, so x-scale type is "time". For non
#timeseries data, use "linear"
vis = Visualization(width=500, height=300)
vis.scales['x'] = Scale(name='x', type='time', range='width',
domain=DataRef(data='table', field="data.idx"))
vis.scales['y'] = Scale(name='y', range='height', type='linear', nice=True,
domain=DataRef(data='table', field="data.val"))
vis.scales['color'] = Scale(name='color', type='ordinal',
domain=DataRef(data='table', field='data.col'),
range='category20')
vis.axes.extend([Axis(type='x', scale='x'),
Axis(type='y', scale='y')])
#Marks
transform = MarkRef(data='table',
transform=[Transform(type='facet', keys=['data.col'])])
enter_props = PropertySet(x=ValueRef(scale='x', field="data.idx"),
y=ValueRef(scale='y', field="data.val"),
fill=ValueRef(scale='color', field='data.col'),
size=ValueRef(value=10))
mark = Mark(type='group', from_=transform,
marks=[Mark(type='symbol',
properties=MarkProperties(enter=enter_props))])
vis.marks.append(mark)
data = Data.from_pandas(price[['GOOG', 'AAPL']])
#Using a Vincent Keyed List here
vis.data['table'] = data
vis.axis_titles(x='Date', y='Price')
vis.legend(title='GOOG vs AAPL')
vis.to_json('vega.json')
#Convenience method
vis = Scatter(price[['GOOG', 'AAPL']])
vis.axis_titles(x='Date', y='Price')
vis.legend(title='GOOG vs AAPL')
vis.colors(brew='RdBu')
vis.to_json('vega.json')