假设我有一分钟的数据,在三天的营业时间从早上8点到下午4点。我想用pandas
绘图函数绘制这些数据:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(51723)
dates = pd.date_range("11/8/2018", "11/11/2018", freq = "min")
df = pd.DataFrame(np.random.rand(len(dates)), index = dates, columns = ['A'])
df = df[(df.index.hour >= 8) & (df.index.hour <= 16)] # filter for business hours
fig, ax = plt.subplots()
df.plot(ax = ax)
plt.show()
但是,plot
函数也在绘图中包含过夜时间,这会导致在此期间意外绘制:
什么是一个好的方法,只规划上午8点到下午4点的预定时间?在
这可以通过在不同的轴上绘制每个日期来完成。但像标签这样的东西在某些情况下会变得局促。在
相关问题 更多 >
编程相关推荐