python - Python 显示时间跨度
问题描述
我创建了一个图表,您可以在其中查看可视化数据和数据趋势。是否可以按时间跨度切割图表?
这是我的图表代码
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
fig, ax = plt.subplots()
ax.grid(True)
year = mdates.YearLocator(month=1)
month = mdates.MonthLocator(interval=3)
year_format = mdates.DateFormatter('%Y')
month_format = mdates.DateFormatter('%m')
ax.xaxis.set_minor_locator(month)
ax.xaxis.grid(True, which = 'minor')
ax.xaxis.set_major_locator(year)
ax.xaxis.set_major_formatter(year_format)
plt.plot(df.index, df['JAN'], c='blue')
plt.plot(decomposition.trend.index, decomposition.trend, c='red')
我有这段代码来缩短图表,但我不知道如何在上面的代码中使用它。
start_date = datetime(2004,1,1)
end_date = datetime(2008,1,1)
df[(start_date<=df.index) & (df.index<=end_date)].plot(grid='on')
解决方案
推荐阅读
- database - Laravel - 如何与从属数据库进行数据库连接
- node.js - 如何使用nodeJS检查PDF中的复选框?
- git - “冲突文件”并且该文件不是我的发布分支的一部分
- servicestack - 如何从 ServiceStack API 获取访问令牌
- angular - Angular & svg - 找不到 Angular 的任何 SVG 标签
- bash - cli和jq,如何在使用unique_by过滤后获取属性值
- java - 如何正确调整大图像的大小?
- mysql - 两行之间的 MySQL 间隔小于 15 分钟
- ios - Swift 5:给定的数据不是有效的 JSON(从 API 加载数据到表视图)
- javascript - Javascript 调整