|
39 | 39 | fig, ax = plt.subplots() |
40 | 40 | ax.plot('date', 'adj_close', data=data) |
41 | 41 |
|
42 | | -# Major ticks every 6 months |
| 42 | +# Major ticks every 6 months. |
43 | 43 | fmt_half_year = mdates.MonthLocator(interval=6) |
44 | 44 | ax.xaxis.set_major_locator(fmt_half_year) |
45 | 45 |
|
46 | | -# Minor ticks every month |
| 46 | +# Minor ticks every month. |
47 | 47 | fmt_month = mdates.MonthLocator() |
48 | 48 | ax.xaxis.set_minor_locator(fmt_month) |
49 | 49 |
|
50 | | -# Text in the x axis will be displayed in 'YYYY-mm' format |
| 50 | +# Text in the x axis will be displayed in 'YYYY-mm' format. |
51 | 51 | ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m')) |
52 | 52 |
|
53 | 53 | # Round to nearest years. |
54 | 54 | datemin = np.datetime64(data['date'][0], 'Y') |
55 | 55 | datemax = np.datetime64(data['date'][-1], 'Y') + np.timedelta64(1, 'Y') |
56 | 56 | ax.set_xlim(datemin, datemax) |
57 | 57 |
|
58 | | -# Format the coords message box |
| 58 | +# Format the coords message box, i.e. the numbers displayed as the cursor moves |
| 59 | +# across the axes within the interactive GUI. |
59 | 60 | ax.format_xdata = mdates.DateFormatter('%Y-%m') |
60 | | -ax.format_ydata = lambda x: '$%1.2f' % x # format the price. |
| 61 | +ax.format_ydata = lambda x: f'${x:.2f}' # Format the price. |
61 | 62 | ax.grid(True) |
62 | 63 |
|
63 | | -# rotates and right aligns the x labels, and moves the bottom of the |
64 | | -# axes up to make room for them |
| 64 | +# Rotates and right aligns the x labels, and moves the bottom of the |
| 65 | +# axes up to make room for them. |
65 | 66 | fig.autofmt_xdate() |
66 | 67 |
|
67 | 68 | plt.show() |
0 commit comments