| 
19 | 19 |                         asfileobj=False)  | 
20 | 20 | gender_degree_data = np.genfromtxt(fname, delimiter=',', names=True)  | 
21 | 21 | 
 
  | 
22 |  | -# These are the colors that will be used in the plot  | 
23 |  | -color_sequence = ['#1f77b4', '#aec7e8', '#ff7f0e', '#ffbb78', '#2ca02c',  | 
24 |  | -                  '#98df8a', '#d62728', '#ff9896', '#9467bd', '#c5b0d5',  | 
25 |  | -                  '#8c564b', '#c49c94', '#e377c2', '#f7b6d2', '#7f7f7f',  | 
26 |  | -                  '#c7c7c7', '#bcbd22', '#dbdb8d', '#17becf', '#9edae5']  | 
27 |  | - | 
28 | 22 | # You typically want your plot to be ~1.33x wider than tall. This plot  | 
29 | 23 | # is a rare exception because of the number of lines being plotted on it.  | 
30 | 24 | # Common sizes: (10, 7.5) and (12, 9)  | 
31 | 25 | fig, ax = plt.subplots(1, 1, figsize=(12, 14))  | 
32 | 26 | 
 
  | 
 | 27 | +# These are the colors that will be used in the plot  | 
 | 28 | +ax.set_prop_cycle(color=[  | 
 | 29 | +    '#1f77b4', '#aec7e8', '#ff7f0e', '#ffbb78', '#2ca02c', '#98df8a',  | 
 | 30 | +    '#d62728', '#ff9896', '#9467bd', '#c5b0d5', '#8c564b', '#c49c94',  | 
 | 31 | +    '#e377c2', '#f7b6d2', '#7f7f7f', '#c7c7c7', '#bcbd22', '#dbdb8d',  | 
 | 32 | +    '#17becf', '#9edae5'])  | 
 | 33 | + | 
33 | 34 | # Remove the plot frame lines. They are unnecessary here.  | 
34 | 35 | ax.spines['top'].set_visible(False)  | 
35 | 36 | ax.spines['bottom'].set_visible(False)  | 
 | 
81 | 82 |              'Math and Statistics': 0.75, 'Architecture': -0.75,  | 
82 | 83 |              'Computer Science': 0.75, 'Engineering': -0.25}  | 
83 | 84 | 
 
  | 
84 |  | -for rank, column in enumerate(majors):  | 
 | 85 | +for column in majors:  | 
85 | 86 |     # Plot each line separately with its own color.  | 
86 | 87 |     column_rec_name = column.replace('\n', '_').replace(' ', '_')  | 
87 | 88 | 
 
  | 
88 |  | -    line = ax.plot(gender_degree_data['Year'],  | 
89 |  | -                   gender_degree_data[column_rec_name],  | 
90 |  | -                   lw=2.5,  | 
91 |  | -                   color=color_sequence[rank])  | 
 | 89 | +    line, = ax.plot('Year', column_rec_name, data=gender_degree_data,  | 
 | 90 | +                    lw=2.5)  | 
92 | 91 | 
 
  | 
93 | 92 |     # Add a text label to the right end of every line. Most of the code below  | 
94 | 93 |     # is adding specific offsets y position because some labels overlapped.  | 
 | 
99 | 98 | 
 
  | 
100 | 99 |     # Again, make sure that all labels are large enough to be easily read  | 
101 | 100 |     # by the viewer.  | 
102 |  | -    ax.text(2011.5, y_pos, column, fontsize=14, color=color_sequence[rank])  | 
 | 101 | +    ax.text(2011.5, y_pos, column, fontsize=14, color=line.get_color())  | 
103 | 102 | 
 
  | 
104 | 103 | # Make the title big enough so it spans the entire plot, but don't make it  | 
105 | 104 | # so big that it requires two lines to show.  | 
 | 
0 commit comments