|
30 | 30 | fig.subplots_adjust(left=.06, right=.75, bottom=.02, top=.94)
|
31 | 31 | # Limit the range of the plot to only where the data is.
|
32 | 32 | # Avoid unnecessary whitespace.
|
33 |
| -ax.set_xlim(1968.5, 2011.1) |
| 33 | +ax.set_xlim(1969.5, 2011.1) |
34 | 34 | ax.set_ylim(-0.25, 90)
|
35 |
| -ax.get_xaxis().get_major_formatter().set_useOffset(False) |
36 | 35 |
|
37 | 36 | # Make sure your axis ticks are large enough to be easily read.
|
38 | 37 | # You don't want your viewers squinting to read your plot.
|
39 | 38 | 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)) |
42 | 42 |
|
43 | 43 | # Provide tick lines across the plot to help your viewers trace along
|
44 | 44 | # the axis ticks. Make sure that the lines are light and small so they
|
45 | 45 | # 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) |
49 | 47 |
|
50 | 48 | # Remove the tick marks; they are unnecessary with the tick lines we just
|
51 | 49 | # plotted.
|
|
100 | 98 | # You can also save it as a PDF, JPEG, etc.
|
101 | 99 | # Just change the file extension in this call.
|
102 | 100 | # plt.savefig('percent-bachelors-degrees-women-usa.png', bbox_inches='tight')
|
| 101 | +plt.show() |
0 commit comments