另一个麻烦是,如果你将鼠标悬停在窗口上,并在 x 和 y 坐标处查看 matplotlib 工具栏([交互式导航](http://matplotlib.org/users/navigation_toolbar.html#navigation-toolbar))的右下角,您会看到 x 位置的格式与刻度标签的格式相同, 例如,“Dec 2004”。 我们想要的是工具栏中的位置具有更高的精确度,例如,鼠标悬停在上面时给我们确切的日期。 为了解决第一个问题,我们可以使用[`matplotlib.figure.Figure.autofmt_xdate()`](http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.autofmt_xdate)。修复第二个问题,我们可以使用`ax.fmt_xdata`属性,该属性可以设置为任何接受标量并返回字符串的函数。 matplotlib 有一些内置的日期格式化器,所以我们将使用其中的一个。
```py
plt.close('all')
fig,ax=plt.subplots(1)
ax.plot(r.date,r.close)
# rotate and align the tick labels so they look better
fig.autofmt_xdate()
# use a more precise date string for the x axis locations in the