8000 FIX the example now works properly + formatting · matplotlib/matplotlib@4954a45 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4954a45

Browse files
committed
FIX the example now works properly + formatting
1 parent 751128c commit 4954a45

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

examples/pylab_examples/stock_demo.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
11
import matplotlib.pyplot as plt
2-
import numpy as np
3-
4-
import matplotlib.cbook as cbook
5-
from matplotlib.ticker import MultipleLocator
6-
72
"""
3+
================
84
Stock Demo Plots
5+
================
96
107
The following example displays Matplotlibs capabilities of creating
118
graphs that can be used for stocks. The example specfically uses
129
Apple and Intel stock data and graphs the normalized prices on the
13-
same plot.
14-
10+
same plot.
1511
"""
1612

13+
14+
import numpy as np
15+
16+
import matplotlib.cbook as cbook
17+
from matplotlib.ticker import MultipleLocator
18+
19+
1720
def get_two_stock_data():
1821
"""
1922
load stock time and price data for two stocks The return values
2023
(d1,p1,d2,p2) are the trade time (in days) and prices for stocks 1
2124
and 2 (intc and aapl)
2225
"""
23-
ticker1, ticker2 = 'INTC', 'AAPL'
24-
2526
file1 = cbook.get_sample_data('INTC.dat.gz')
2627
file2 = cbook.get_sample_data('AAPL.dat.gz')
27-
M1 = fromstring(file1.read(), '<d')
28+
M1 = np.fromstring(file1.read(), '<d')
2829

29-
M1 = resize(M1, (M1.shape[0]//2, 2))
30+
M1 = np.resize(M1, (M1.shape[0]//2, 2))
3031

31-
M2 = fromstring(file2.read(), '<d')
32-
M2 = resize(M2, (M2.shape[0]//2, 2))
32+
M2 = np.fromstring(file2.read(), '<d')
33+
M2 = np.resize(M2, (M2.shape[0]//2, 2))
3334

3435
d1, p1 = M1[:, 0], M1[:, 1]
3536
d2, p2 = M2[:, 0], M2[:, 1]
3637
return (d1, p1, d2, p2)
3738

39+
3840
d1, p1, d2, p2 = get_two_stock_data()
3941

4042
fig, ax = plt.subplots()
41-
lines1 = plt.plot(d1, p1, 'b', label="INTC")
42-
lines2 = plt.plot(d2, p2, 'r', label="AAPL")
43-
plt.xlabel('Days')
44-
plt.ylabel('Normalized price')
45-
plt.xlim(0, 3)
43+
lines1 = ax.plot(d1, p1, 'b', label="INTC")
44+
lines2 = ax.plot(d2, p2, 'r', label="AAPL")
45+
ax.set_xlabel('Days')
46+
ax.set_ylabel('Normalized price')
47+
ax.set_xlim(0, 3)
4648
ax.xaxis.set_major_locator(MultipleLocator(1))
4749

48-
plt.title('INTC vs AAPL')
49-
plt.legend()
50+
ax.set_title('INTC vs AAPL')
51+
ax.legend()
5052

5153
plt.show()

0 commit comments

Comments
 (0)
0