diff --git a/examples/text_labels_and_annotations/date.py b/examples/text_labels_and_annotations/date.py index 41944fa2cc53..c8287fffcdc6 100644 --- a/examples/text_labels_and_annotations/date.py +++ b/examples/text_labels_and_annotations/date.py @@ -39,15 +39,15 @@ fig, ax = plt.subplots() ax.plot('date', 'adj_close', data=data) -# Major ticks every 6 months +# Major ticks every 6 months. fmt_half_year = mdates.MonthLocator(interval=6) ax.xaxis.set_major_locator(fmt_half_year) -# Minor ticks every month +# Minor ticks every month. fmt_month = mdates.MonthLocator() ax.xaxis.set_minor_locator(fmt_month) -# Text in the x axis will be displayed in 'YYYY-mm' format +# Text in the x axis will be displayed in 'YYYY-mm' format. ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m')) # Round to nearest years. @@ -55,13 +55,14 @@ datemax = np.datetime64(data['date'][-1], 'Y') + np.timedelta64(1, 'Y') ax.set_xlim(datemin, datemax) -# Format the coords message box +# Format the coords message box, i.e. the numbers displayed as the cursor moves +# across the axes within the interactive GUI. ax.format_xdata = mdates.DateFormatter('%Y-%m') -ax.format_ydata = lambda x: '$%1.2f' % x # format the price. +ax.format_ydata = lambda x: f'${x:.2f}' # Format the price. ax.grid(True) -# rotates and right aligns the x labels, and moves the bottom of the -# axes up to make room for them +# Rotates and right aligns the x labels, and moves the bottom of the +# axes up to make room for them. fig.autofmt_xdate() plt.show()