Plot Forex data in GUI using PyQT5 Python, Embed Matplotlib

Publicado em: 02 Abril 2020
no canal de: Program in Pyqt5
1,368
11

Plotting ForexData(any data) on GUI using PyQT5 and Matplotlib
you can find program below... you need to add folder location and place the file in the folder.
Let me know your comments

#---------------------------------------------------------------

from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QCalendarWidget,QDateEdit
from PyQt5 import QtWidgets
from PyQt5.QtGui import QColor,QPalette
import sys
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import numpy as np
import os
import pandas as pd



class Window(QMainWindow):


def __init__(self):
super().__init__()

Title for GUI , top/left is how far from top left corner desktop screen , width/height is for GUI
title = "FOREX Plotting using PyQT5"
top = 100
left = 100
width = 1200
height = 800
GUI property
self.setWindowTitle(title)
self.setGeometry(top, left, width, height)
self.setAutoFillBackground(True)
palette = self.palette()
palette.setColor(QPalette.Window, QColor(0, 220, 255, 127))
self.setPalette(palette)

This is for the canvas created to use Matplotlib figure
#MyStaticMplCanvas is called to a object called canvas
#canvas function plot is called to plot random numbers
self.canvas = MyStaticMplCanvas(self, width=8, height=6)
self.canvas.move(250, 100)
self.input_List = pd.DataFrame(np.random.randint(0,100,size=(15, 2)), columns=list('AB'))
self.canvas.plot(self.input_List)

self.Readbutton = QPushButton("Read Forex data",self)
self.Readbutton.move(40, 150)
self.Readbutton.clicked.connect(self.ButtonAction)
self.Read_DataPressed = 0

self.displaybutton = QPushButton("Plot Data", self)
self.displaybutton.move(40, 250)
self.displaybutton.clicked.connect(self.ButtonAction2)



def ButtonAction(self):
files = ['EURUSD_M1_202002', 'EURGBP_M1_202002']

def symbol_to_path(file, base_dir=r'Folder Location starting with C: or D:'):
"""Return CSV file path given ticker symbol."""
return os.path.join(base_dir, '{}.xlsx'.format(str(file)))

def get_data(file):
for file in files:
df_temp = pd.read_excel(symbol_to_path(file),
index_col=0,
usecols=[0, 1],
header=None,
names=['date', 'value'])

df_temp = df_temp.rename(columns={'value': file})

if file == 'EURUSD_M1_202002':
df = df_temp
else:
df = df.join(df_temp)
return df

self.df = get_data(files)
self.df = self.df.fillna(method='ffill')
self.df = self.df.fillna(method='bfill')
df = self.df
self.Read_DataPressed = 1

def ButtonAction2(self):
if self.Read_DataPressed == 1:
window.canvas.plot(self.df)
else:
print('Read the Data First')


class MyMplCanvas(FigureCanvas):
"""Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""

def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
FigureCanvas.__init__(self, fig)
self.setParent(parent)

FigureCanvas.setSizePolicy(self,
QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)

def plot(self):
pass


class MyStaticMplCanvas(MyMplCanvas):

def plot(self,input_List):
self.figure.clear()
ax =self.figure.add_subplot(111)
input_List.plot(ax=ax)
self.draw()

app = QApplication(sys.argv)
window = Window()
window.show()
app.exec()


Nesta página do site você pode assistir ao vídeo on-line Plot Forex data in GUI using PyQT5 Python, Embed Matplotlib duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Program in Pyqt5 02 Abril 2020, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 1,368 vezes e gostou 11 espectadores. Boa visualização!