|
1 | | -from pylab import plotfile, show, gca |
| 1 | +import matplotlib.pyplot as plt |
| 2 | +import numpy as np |
| 3 | + |
2 | 4 | import matplotlib.cbook as cbook |
3 | 5 |
|
4 | 6 | fname = cbook.get_sample_data('msft.csv', asfileobj=False) |
5 | 7 | fname2 = cbook.get_sample_data('data_x_x2_x3.csv', asfileobj=False) |
6 | 8 |
|
7 | 9 | # test 1; use ints |
8 | | -plotfile(fname, (0, 5, 6)) |
| 10 | +plt.plotfile(fname, (0, 5, 6)) |
9 | 11 |
|
10 | 12 | # test 2; use names |
11 | | -plotfile(fname, ('date', 'volume', 'adj_close')) |
| 13 | +plt.plotfile(fname, ('date', 'volume', 'adj_close')) |
12 | 14 |
|
13 | 15 | # test 3; use semilogy for volume |
14 | | -plotfile(fname, ('date', 'volume', 'adj_close'), plotfuncs={'volume': 'semilogy'}) |
| 16 | +plt.plotfile(fname, ('date', 'volume', 'adj_close'), |
| 17 | + plotfuncs={'volume': 'semilogy'}) |
15 | 18 |
|
16 | 19 | # test 4; use semilogy for volume |
17 | | -plotfile(fname, (0, 5, 6), plotfuncs={5: 'semilogy'}) |
| 20 | +plt.plotfile(fname, (0, 5, 6), plotfuncs={5: 'semilogy'}) |
18 | 21 |
|
19 | 22 | # test 5; single subplot |
20 | | -plotfile(fname, ('date', 'open', 'high', 'low', 'close'), subplots=False) |
| 23 | +plt.plotfile(fname, ('date', 'open', 'high', 'low', 'close'), subplots=False) |
21 | 24 |
|
22 | 25 | # test 6; labeling, if no names in csv-file |
23 | | -plotfile(fname2, cols=(0, 1, 2), delimiter=' ', |
24 | | - names=['$x$', '$f(x)=x^2$', '$f(x)=x^3$']) |
| 26 | +plt.plotfile(fname2, cols=(0, 1, 2), delimiter=' ', |
| 27 | + names=['$x$', '$f(x)=x^2$', '$f(x)=x^3$']) |
25 | 28 |
|
26 | 29 | # test 7; more than one file per figure--illustrated here with a single file |
27 | | -plotfile(fname2, cols=(0, 1), delimiter=' ') |
28 | | -plotfile(fname2, cols=(0, 2), newfig=False, delimiter=' ') # use current figure |
29 | | -gca().set_xlabel(r'$x$') |
30 | | -gca().set_ylabel(r'$f(x) = x^2, x^3$') |
| 30 | +plt.plotfile(fname2, cols=(0, 1), delimiter=' ') |
| 31 | +plt.plotfile(fname2, cols=(0, 2), newfig=False, |
| 32 | + delimiter=' ') # use current figure |
| 33 | +plt.xlabel(r'$x$') |
| 34 | +plt.ylabel(r'$f(x) = x^2, x^3$') |
31 | 35 |
|
32 | 36 | # test 8; use bar for volume |
33 | | -plotfile(fname, (0, 5, 6), plotfuncs={5: 'bar'}) |
| 37 | +plt.plotfile(fname, (0, 5, 6), plotfuncs={5: 'bar'}) |
34 | 38 |
|
35 | | -show() |
| 39 | +plt.show() |
0 commit comments