8000 added in get_two_stock_demo into file so no more imports · matplotlib/matplotlib@e8c4ef1 · GitHub
[go: up one dir, main page]

Skip to content

Commit e8c4ef1

Browse files
author
Salil Vanvari
committed
added in get_two_stock_demo into file so no more imports
1 parent fd14063 commit e8c4ef1

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

examples/pylab_examples/stock_demo.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,28 @@
22
import numpy as np
33

44
from matplotlib.ticker import MultipleLocator
5-
from data_helper import get_two_stock_data
5+
6+
def get_two_stock_data():
7+
"""
8+
load stock time and price data for two stocks The return values
9+
(d1,p1,d2,p2) are the trade time (in days) and prices for stocks 1
10+
and 2 (intc and aapl)
11+
"""
12+
ticker1, ticker2 = 'INTC', 'AAPL'
13+
14+
file1 = cbook.get_sample_data('INTC.dat.gz')
15+
file2 = cbook.get_sample_data('AAPL.dat.gz')
16+
M1 = fromstring(file1.read(), '<d')
17+
18+
M1 = resize(M1, (M1.shape[0]//2, 2))
19+
20+
M2 = fromstring(file2.read(), '<d')
21+
M2 = resize(M2, (M2.shape[0]//2, 2))
22+
23+
d1, p1 = M1[:, 0], M1[:, 1]
24+
d2, p2 = M2[:, 0], M2[:, 1]
25+
return (d1, p1, d2, p2)
26+
627

728
d1, p1, d2, p2 = get_two_stock_data()
829

@@ -11,7 +32,7 @@
1132
lines2 = plt.plot(d2, p2, 'r', label="AAPL")
1233
plt.xlabel('Days')
1334
plt.ylabel('Normalized price')
14-
plt.xlim(0, 3)
35+
plt.xlim(0, 3 )
1536
ax.xaxis.set_major_locator(MultipleLocator(1))
1637

1738
plt.title('INTC vs AAPL')

0 commit comments

Comments
 (0)
0