结果
year Month Min_days Avg_days Median_days Count MonthName-Year
2015 1 9 12.56 10 4 2015-Jan
2015 2 10 13.67 9 3 2015-Feb
........................................................
2016 12 12 15.788 19 2 2016-Dec
and so on...
我创建了一个折线图,绘制了min_days,avg_days,median_days,根据月份和 年说。用于此的代码(效果很好):
import matplotlib.pyplot as plt
from matplotlib import dates as mdates
result = freq_start_month_year_to_date_1(df,'Jan','2015','Dec','2019')
result['Date'] = pd.to_datetime(result[['Year', 'Month']].assign(Day=1))
# Plot the data
fig, ax = plt.subplots(figsize=(10, 2))
for col in ['Min_days','Avg_days','Median_days','Count']:
ax.plot(result['Date'], result[col], label=col)
years = mdates.YearLocator() # only print label for the years
months = mdates.MonthLocator() # mark months as ticks
years_fmt = mdates.DateFormatter('%Y')
ax.xaxis.set_major_locator(years)
ax.xaxis.set_minor_locator(months)
ax.xaxis.set_major_formatter(years_fmt)
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
现在,我希望能够在悬停在绘图中的同时查看数据。知道怎么做吗?