【发布时间】:2019-02-15 12:53:22
【问题描述】:
我的代码:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
lot_size = 3750
min_vol = 60
path = 'C:\\Data\\ONGC19FEBFUT.txt'
df = pd.read_csv(path, sep=",")
df.columns = ['Date','Time','Price','volume']
df['Volume'] = np.where((df.volume/lot_size) < min_vol, 0, (df.volume/lot_size))
df["Time"] = pd.to_datetime(df['Time'])
df.plot(x="Time",y='Price', rot=0, color='g')
plt.title("Date: " + str(df['Date'].iloc[0]))
dff = df[df.Volume > min_vol].reset_index(drop=True)
dff = dff[['Time','Price','Volume']]
print(dff)
dict = dff.to_dict('index')
for x in range(0, len(dict)):
plt.axhline(y=dict[x]['Price'],linewidth=1, color='blue')
plt.subplots_adjust(left=0.05, bottom=0.06, right=0.95, top=0.96, wspace=None, hspace=None)
plt.show()
Dataframe dff 给出要在图表上绘制的价格值。我想将要绘制的价格值分隔为每 30 分钟持续时间,即要在时间范围内绘制 09:00 到 09:30 的价格值,要在此时间范围内绘制 09:30 到 10:00 的价格值等等。 我想限制每 30 分钟时间范围内的水平价格线。
dff 输出:
Time Price Volume
0 2019-02-15 09:15:02 132.90 111.0
1 2019-02-15 09:15:03 134.15 78.0
2 2019-02-15 11:14:46 132.65 68.0
3 2019-02-15 11:27:24 131.95 73.0
4 2019-02-15 12:40:36 129.50 176.0
5 2019-02-15 13:42:52 129.90 75.0
6 2019-02-15 13:52:26 130.05 71.0
7 2019-02-15 13:52:40 129.70 99.0
【问题讨论】:
标签: python python-3.x pandas dataframe matplotlib