|
33 | 33 | # A global x- or y-label can be set using the `.FigureBase.supxlabel` and
|
34 | 34 | # `.FigureBase.supylabel` methods.
|
35 | 35 |
|
36 |
| -fig, axs = plt.subplots(3, 5, figsize=(8, 5), layout='constrained', |
37 |
| - sharex=True, sharey=True) |
38 | 36 |
|
39 |
| -fname = get_sample_data('percent_bachelors_degrees_women_usa.csv', |
40 |
| - asfileobj=False) |
41 |
| -gender_degree_data = np.genfromtxt(fname, delimiter=',', names=True) |
| 37 | +def convertdate(x): |
| 38 | + return np.datetime64(x, 'D') |
42 | 39 |
|
43 |
| -majors = ['Health Professions', 'Public Administration', 'Education', |
44 |
| - 'Psychology', 'Foreign Languages', 'English', |
45 |
| - 'Art and Performance', 'Biology', |
46 |
| - 'Agriculture', 'Business', |
47 |
| - 'Math and Statistics', 'Architecture', 'Physical Sciences', |
48 |
| - 'Computer Science', 'Engineering'] |
| 40 | +fname = get_sample_data('Stocks.csv', asfileobj=False) |
| 41 | +stocks = np.genfromtxt(fname, encoding='utf-8', delimiter=',', |
| 42 | + names=True, dtype=None, converters={0: convertdate}, |
| 43 | + skip_header=1) |
49 | 44 |
|
| 45 | +fig, axs = plt.subplots(4, 2, figsize=(9, 5), layout='constrained', |
| 46 | + sharex=True, sharey=True) |
50 | 47 | for nn, ax in enumerate(axs.flat):
|
51 |
| - ax.set_xlim(1969.5, 2011.1) |
52 |
| - column = majors[nn] |
53 |
| - column_rec_name = column.replace('\n', '_').replace(' ', '_') |
54 |
| - |
55 |
| - line, = ax.plot('Year', column_rec_name, data=gender_degree_data, |
56 |
| - lw=2.5) |
57 |
| - ax.set_title(column, fontsize='small', loc='left') |
58 |
| - ax.set_ylim([0, 100]) |
59 |
| - ax.grid() |
| 48 | + column_name = stocks.dtype.names[1+nn] |
| 49 | + y = stocks[column_name] |
| 50 | + line, = ax.plot(stocks['Date'], y / np.nanmax(y), lw=2.5) |
| 51 | + ax.set_title(column_name, fontsize='small', loc='left') |
60 | 52 | fig.supxlabel('Year')
|
61 |
| -fig.supylabel('Percent Degrees Awarded To Women') |
62 |
| - |
63 |
| -plt.show() |
| 53 | +fig.supylabel('Stock price relative to max') |
0 commit comments