Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da2842e

Browse files
committed
pep8 enforcement, different figure call
1 parent b3fb454 commit da2842e

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

examples/showcase/bachelors_degrees_by_gender.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@
1414
# You typically want your plot to be ~1.33x wider than tall. This plot
1515
# is a rare exception because of the number of lines being plotted on it.
1616
# Common sizes: (10, 7.5) and (12, 9)
17-
plt.figure(figsize=(12, 14))
17+
fig, ax = plt.subplots(1, 1, figsize=(12, 14))
1818

19-
# Remove the plot frame lines. They are unnecessary chartjunk.
20-
ax = plt.subplot(111)
19+
# Remove the plot frame lines. They are unnecessary here.
2120
ax.spines['top'].set_visible(False)
2221
ax.spines['bottom'].set_visible(False)
2322
ax.spines['right'].set_visible(False)
2423
ax.spines['left'].set_visible(False)
2524

26-
# Ensure that the axis ticks only show up on the bottom and left of the plot.
27-
# Ticks on the right and top of the plot are generally unnecessary chartjunk.
25+
# Ensure that the axis ticks only show up on the bottom and left of the plot.
26+
# Ticks on the right and top of the plot are generally unnecessary.
2827
ax.get_xaxis().tick_bottom()
2928
ax.get_yaxis().tick_left()
3029

@@ -36,18 +35,20 @@
3635
# Make sure your axis ticks are large enough to be easily read.
3736
# You don't want your viewers squinting to read your plot.
3837
plt.xticks(range(1970, 2011, 10), fontsize=14)
39-
plt.yticks(range(0, 91, 10), ['{}%'.format(x) for x in range(0, 91, 10)], fontsize=14)
38+
plt.yticks(range(0, 91, 10), ['{}%'.format(x)
39+
for x in range(0, 91, 10)], fontsize=14)
4040

41-
# Provide tick lines across the plot to help your viewers trace along
42-
# the axis ticks. Make sure that the lines are light and small so they
43-
# don't obscure the primary data lines.
44-
for y in range(10, 91, 10):
41+
# Provide tick lines across the plot to help your viewers trace along
42+
# the axis ticks. Make sure that the lines are light and small so they
43+
# don't obscure the primary data lines.
44+
for y in range(10, 91, 10):
4545
plt.plot(range(1969, 2012), [y] * len(range(1969, 2012)), '--',
46-
lw=0.5, color='black', alpha=0.3)
46+
lw=0.5, color='black', alpha=0.3)
4747

48-
# Remove the tick marks; they are unnecessary with the tick lines we just plotted.
49-
plt.tick_params(axis='both', which='both', bottom='off', top='off',
50-
labelbottom='on', left='off', right='off', labelleft='on')
48+
# Remove the tick marks; they are unnecessary with the tick lines we just
49+
# plotted.
50+
plt.tick_params(axis='both', which='both', bottom='off', top='off',
51+
labelbottom='on', left='off', right='off', labelleft='on')
5152

5253
# Now that the plot is prepared, it's time to actually plot the data!
5354
# Note that I plotted the majors in order of the highest % in the final year.
@@ -91,7 +92,7 @@
9192
# Note that if the title is descriptive enough, it is unnecessary to include
9293
# axis labels; they are self-evident, in this plot's case.
9394
plt.title('Percentage of Bachelor\'s degrees conferred to women in '
94-
'the U.S.A. by major (1970-2011)\n', fontsize=18, ha='center')
95+
'the U.S.A. by major (1970-2011)\n', fontsize=18, ha='center')
9596

9697
# Finally, save the figure as a PNG.
9798
# You can also save it as a PDF, JPEG, etc.

0 commit comments

Comments
 (0)