简体   繁体   English

熊猫时间序列图-将鼠标悬停在线上时显示日期

[英]Pandas timeseries plot — show date when hovering mouse over the line

I am plotting a pandas Series where the index is date by date. 我正在绘制一个熊猫系列,其中索引是按日期排序。 When I say series.plot(), a chart is generated correctly. 当我说series.plot()时,会正确生成一个图表。 The problem is that when I hover the mouse over interesting points on the chart, it only shows the Month and Year of that point. 问题是,当我将鼠标悬停在图表上的有趣点上时,它仅显示该点的月份和年份。 It does not show the exact date of that point. 它没有显示该点的确切日期。

Below is a sample of the code. 下面是代码示例。 Depending on luck, when I mouse over the line, sometimes I see the exact date displayed on the status bar but sometimes I only see year and month. 根据运气,当我将鼠标悬停在行上时,有时会看到状态栏上显示的确切日期,但有时我只会看到年和月。

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
idx = pd.date_range('2011-1-1', '2015-1-1')
x = pd.Series(np.cumsum(np.random.randn(len(idx))), idx)

df = pd.DataFrame(x)
df.plot()
plt.show()

Is there any way to display the exact date? 有什么办法可以显示确切的日期? How does matplotlib control what to display on status bar? matplotlib如何控制在状态栏上显示的内容? I wonder it has something to do with pandas changing the default configuration after some code is called. 我不知道这与熊猫在调用某些代码后更改默认配置有关。

When launching your code everything seems to be working and a complete date (the x-coordinate) is shown in the status bar all the time. 启动代码时,一切似乎都可以正常工作,并且状态栏中会始终显示完整的日期(x坐标)。 But the two coordinates are shown also when I am not directly over the graph (so it is difficult to know the actual values of your graph). 但是,当我不在图形上方时,也会显示两个坐标(因此很难知道图形的实际值)。 Are you looking for a tooltip that shows the exact date, when mousing over the graph, or are the right values (complete dates) in the status bar enough? 当您将鼠标悬停在图表上时,您是否正在寻找显示确切日期的工具提示,或者状态栏中的正确值(完整日期)足够? Can you make a screenshot of how your problem looks like, when it occurs and provide details on the versions you are using? 您能否截屏显示问题的外观,发生的时间,并提供有关所使用版本的详细信息? I am on matplotlib 1.4.3 and numpy 1.9.2 combined with pandas 0.15.2. 我正在使用matplotlib 1.4.3和numpy 1.9.2以及熊猫0.15.2。

Also have a look at the matplotlib recipes ( http://matplotlib.org/users/recipes.html )! 还可以看看matplotlib食谱( http://matplotlib.org/users/recipes.html )! Section "Fixing common date annoyances" sounds very similar to your problem! 听起来“解决常见的日期烦恼”部分与您的问题非常相似!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM