|
10 | 10 | as an alternative to a conventional legend.
|
11 | 11 | """
|
12 | 12 |
|
| 13 | +import numpy as np |
13 | 14 | import matplotlib.pyplot as plt
|
14 |
| -from matplotlib.mlab import csv2rec |
15 | 15 | from matplotlib.cbook import get_sample_data
|
16 | 16 |
|
17 |
| -with get_sample_data('percent_bachelors_degrees_women_usa.csv') as fname: |
18 |
| - gender_degree_data = csv2rec(fname) |
| 17 | + |
| 18 | +fname = get_sample_data('percent_bachelors_degrees_women_usa.csv', |
| 19 | + asfileobj=False) |
| 20 | +gender_degree_data = np.genfromtxt(fname, delimiter=',', names=True) |
19 | 21 |
|
20 | 22 | # These are the colors that will be used in the plot
|
21 | 23 | color_sequence = ['#1f77b4', '#aec7e8', '#ff7f0e', '#ffbb78', '#2ca02c',
|
|
59 | 61 |
|
60 | 62 | # Remove the tick marks; they are unnecessary with the tick lines we just
|
61 | 63 | # plotted.
|
62 |
| -plt.tick_params(axis='both', which='both', bottom='off', top='off', |
63 |
| - labelbottom='on', left='off', right='off', labelleft='on') |
| 64 | +plt.tick_params(axis='both', which='both', bottom=False, top=False, |
| 65 | + labelbottom=True, left=False, right=False, labelleft=True) |
64 | 66 |
|
65 | 67 | # Now that the plot is prepared, it's time to actually plot the data!
|
66 | 68 | # Note that I plotted the majors in order of the highest % in the final year.
|
|
80 | 82 |
|
81 | 83 | for rank, column in enumerate(majors):
|
82 | 84 | # Plot each line separately with its own color.
|
83 |
| - column_rec_name = column.replace('\n', '_').replace(' ', '_').lower() |
| 85 | + column_rec_name = column.replace('\n', '_').replace(' ', '_') |
84 | 86 |
|
85 |
| - line = plt.plot(gender_degree_data.year, |
| 87 | + line = plt.plot(gender_degree_data['Year'], |
86 | 88 | gender_degree_data[column_rec_name],
|
87 | 89 | lw=2.5,
|
88 | 90 | color=color_sequence[rank])
|
|
0 commit comments