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 ac6fc05

Browse filesBrowse files
committed
Update bachelors_degree_by_gender example.
Use plt.grid() instead of manually adding grid lines (this requires slightly changing the xlims to have a similar spacing). Use FuncFormatters instead of fixed tick labels, both for generality and so that the interactive cursor position text is properly formatted. Add a `show()` at the end.
1 parent 88ce601 commit ac6fc05
Copy full SHA for ac6fc05

File tree

Expand file treeCollapse file tree

1 file changed

+6
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-7
lines changed

‎examples/showcase/bachelors_degrees_by_gender.py

Copy file name to clipboardExpand all lines: examples/showcase/bachelors_degrees_by_gender.py
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,20 @@
3030
fig.subplots_adjust(left=.06, right=.75, bottom=.02, top=.94)
3131
# Limit the range of the plot to only where the data is.
3232
# Avoid unnecessary whitespace.
33-
ax.set_xlim(1968.5, 2011.1)
33+
ax.set_xlim(1969.5, 2011.1)
3434
ax.set_ylim(-0.25, 90)
35-
ax.get_xaxis().get_major_formatter().set_useOffset(False)
3635

3736
# Make sure your axis ticks are large enough to be easily read.
3837
# You don't want your viewers squinting to read your plot.
3938
plt.xticks(range(1970, 2011, 10), fontsize=14)
40-
plt.yticks(range(0, 91, 10), ['{0}%'.format(x)
41-
for x in range(0, 91, 10)], fontsize=14)
39+
plt.yticks(range(0, 91, 10), fontsize=14)
40+
ax.xaxis.set_major_formatter(plt.FuncFormatter('{:.0f}'.format))
41+
ax.yaxis.set_major_formatter(plt.FuncFormatter('{:.0f}%'.format))
4242

4343
# Provide tick lines across the plot to help your viewers trace along
4444
# the axis ticks. Make sure that the lines are light and small so they
4545
# don't obscure the primary data lines.
46-
for y in range(10, 91, 10):
47-
plt.plot(range(1969, 2012), [y] * len(range(1969, 2012)), '--',
48-
lw=0.5, color='black', alpha=0.3)
46+
plt.grid(True, 'major', 'y', ls='--', lw=.5, c='k', alpha=.3)
4947

5048
# Remove the tick marks; they are unnecessary with the tick lines we just
5149
# plotted.
@@ -100,3 +98,4 @@
10098
# You can also save it as a PDF, JPEG, etc.
10199
# Just change the file extension in this call.
102100
# plt.savefig('percent-bachelors-degrees-women-usa.png', bbox_inches='tight')
101+
plt.show()

0 commit comments

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