Skip to content

Commit 099c173

Browse files
authored
Merge pull request #19204 from rcomer/date-tick-example
DOC: Clarify Date Format Example
2 parents f2c5b37 + 18148d7 commit 099c173

File tree

1 file changed

+8
-7
lines changed
  • examples/text_labels_and_annotations

1 file changed

+8
-7
lines changed

examples/text_labels_and_annotations/date.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,30 @@
3939
fig, ax = plt.subplots()
4040
ax.plot('date', 'adj_close', data=data)
4141

42-
# Major ticks every 6 months
42+
# Major ticks every 6 months.
4343
fmt_half_year = mdates.MonthLocator(interval=6)
4444
ax.xaxis.set_major_locator(fmt_half_year)
4545

46-
# Minor ticks every month
46+
# Minor ticks every month.
4747
fmt_month = mdates.MonthLocator()
4848
ax.xaxis.set_minor_locator(fmt_month)
4949

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.
5151
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))
5252

5353
# Round to nearest years.
5454
datemin = np.datetime64(data['date'][0], 'Y')
5555
datemax = np.datetime64(data['date'][-1], 'Y') + np.timedelta64(1, 'Y')
5656
ax.set_xlim(datemin, datemax)
5757

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.
5960
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.
6162
ax.grid(True)
6263

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.
6566
fig.autofmt_xdate()
6667

6768
plt.show()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy