Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a4a6306

Browse filesBrowse files
committed
Simplify bachelors degree example using new features.
1 parent c3ce41f commit a4a6306
Copy full SHA for a4a6306

File tree

Expand file treeCollapse file tree

1 file changed

+11
-12
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-12
lines changed

‎examples/showcase/bachelors_degrees_by_gender.py

Copy file name to clipboardExpand all lines: examples/showcase/bachelors_degrees_by_gender.py
+11-12Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
asfileobj=False)
2020
gender_degree_data = np.genfromtxt(fname, delimiter=',', names=True)
2121

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-
2822
# You typically want your plot to be ~1.33x wider than tall. This plot
2923
# is a rare exception because of the number of lines being plotted on it.
3024
# Common sizes: (10, 7.5) and (12, 9)
3125
fig, ax = plt.subplots(1, 1, figsize=(12, 14))
3226

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+
3334
# Remove the plot frame lines. They are unnecessary here.
3435
ax.spines['top'].set_visible(False)
3536
ax.spines['bottom'].set_visible(False)
@@ -81,14 +82,12 @@
8182
'Math and Statistics': 0.75, 'Architecture': -0.75,
8283
'Computer Science': 0.75, 'Engineering': -0.25}
8384

84-
for rank, column in enumerate(majors):
85+
for column in majors:
8586
# Plot each line separately with its own color.
8687
column_rec_name = column.replace('\n', '_').replace(' ', '_')
8788

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)
9291

9392
# Add a text label to the right end of every line. Most of the code below
9493
# is adding specific offsets y position because some labels overlapped.
@@ -99,7 +98,7 @@
9998

10099
# Again, make sure that all labels are large enough to be easily read
101100
# 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())
103102

104103
# Make the title big enough so it spans the entire plot, but don't make it
105104
# so big that it requires two lines to show.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.