|
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( |
| 17 | + fname, |
| 18 | + ('date', |
| 19 | + 'volume', |
| 20 | + 'adj_close'), |
| 21 | + plotfuncs={ |
| 22 | + 'volume': 'semilogy'}) |
15 | 23 |
|
16 | 24 | # test 4; use semilogy for volume
|
17 |
| -plotfile(fname, (0, 5, 6), plotfuncs={5: 'semilogy'}) |
| 25 | +plt.plotfile(fname, (0, 5, 6), plotfuncs={5: 'semilogy'}) |
18 | 26 |
|
19 | 27 | # test 5; single subplot
|
20 |
| -plotfile(fname, ('date', 'open', 'high', 'low', 'close'), subplots=False) |
| 28 | +plt.plotfile(fname, ('date', 'open', 'high', 'low', 'close'), subplots=False) |
21 | 29 |
|
22 | 30 | # 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$']) |
| 31 | +plt.plotfile(fname2, cols=(0, 1, 2), delimiter=' ', |
| 32 | + names=['$x$', '$f(x)=x^2$', '$f(x)=x^3$']) |
25 | 33 |
|
26 | 34 | # 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$') |
| 35 | +plt.plotfile(fname2, cols=(0, 1), delimiter=' ') |
| 36 | +plt.plotfile( |
| 37 | + fname2, |
| 38 | + cols=( |
| 39 | + 0, |
| 40 | + 2), |
| 41 | + newfig=False, |
| 42 | + delimiter=' ') # use current figure |
| 43 | +plt.xlabel(r'$x$') |
| 44 | +plt.ylabel(r'$f(x) = x^2, x^3$') |
31 | 45 |
|
32 | 46 | # test 8; use bar for volume
|
33 |
| -plotfile(fname, (0, 5, 6), plotfuncs={5: 'bar'}) |
| 47 | +plt.plotfile(fname, (0, 5, 6), plotfuncs={5: 'bar'}) |
34 | 48 |
|
35 |
| -show() |
| 49 | +plt.show() |
0 commit comments