-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathQMatplotlib.py
executable file
·87 lines (64 loc) · 2.59 KB
/
QMatplotlib.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import sys
import numpy as np
import pandas as pd
from PyQt5.QtWidgets import QDialog, QApplication, QPushButton, QVBoxLayout
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt
#from matplotlib.finance import candlestick2_ohlc
from mpl_finance import candlestick2_ohlc
import random
class QMatplotlib(QDialog):
def __init__(self, parent=None):
super(QMatplotlib, self).__init__(parent)
pd.set_option("display.precision", 10)
# a figure instance to plot on
self.figure = plt.figure()
# this is the Canvas Widget that displays the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
# this is the Navigation widget
# it takes the Canvas widget and a parent
self.toolbar = NavigationToolbar(self.canvas, self)
# Just some button connected to `plot` method
self.button = QPushButton('Plot')
self.button.clicked.connect(self.plot)
# set the layout
layout = QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
layout.addWidget(self.button)
self.setLayout(layout)
#store array
self.prevision = []
self.ordercolumns = ['DateTime', 'Open', 'Close', 'High', 'Low']
self.currentData = pd.DataFrame({'DateTime': [], 'Open': [], 'Close': [], 'High': [], 'Low': []})
def plot(self):
''' plot some random stuff '''
# random data
#data = [random.random() for i in range(50)]
# create an axis
ax = self.figure.add_subplot(111)
# discards the old graph
# ax.hold(False) # deprecated, see above
print self.currentData['Open'], self.currentData['High'], self.currentData['Low'], self.currentData['Close']
candlestick2_ohlc(ax, self.currentData['Open'], self.currentData['High'], self.currentData['Low'], self.currentData['Close'], width=0.6)
# plot data
#ax.plot(data, 'x-')
# refresh canvas
self.canvas.draw()
def addDataframe(self, df):
self.currentData = df
def addPrevision(self, val):
pass
def clear(self):
self.figure.clear()
if __name__ == '__main__':
import pandasmanager
app = QApplication(sys.argv)
main = QMatplotlib()
test = pandasmanager.PandasManager()
df = test.readAllDataframe()
main.addDataframe(df=df)
main.show()
sys.exit(app.exec_())