-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter.py
More file actions
36 lines (29 loc) · 1.2 KB
/
plotter.py
File metadata and controls
36 lines (29 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pandas as pd
import mplfinance as mpf
import matplotlib.animation as animation
import matplotlib.pyplot as plt
class Plotter():
def __init__(self, periods):
self.resample_map ={'open' :'first',
'high' :'max' ,
'low' :'min' ,
'close':'last' }
self.resample_period = periods
plt.ion() # <-- work in "interactive mode"
self.df = pd.DataFrame()
self.fig = mpf.figure(figsize=(11,8))
self.ax = self.fig.add_subplot(1,1,1,style='blueskies')
# ax1 = fig.add_subplot(2,1,2,style='blueskies')
def plot(self, tick):
# global df, ax
temp_df = pd.DataFrame()
temp_df = temp_df.append(tick, ignore_index=True)
temp_df = temp_df.set_index('time')
temp_df.index = pd.to_datetime(temp_df.index)
self.df = self.df.append(temp_df)
rs = self.df.resample(self.resample_period).agg(self.resample_map).dropna()
self.ax.clear()
mpf.plot(rs,ax=self.ax,type='candle', block=False)
plt.show()
plt.pause(0.001)
## 1min and upwards plot needs to be updated based on the historical data as ticks are not the complete picture