Загрузить файлы в «GraphWidget»

This commit is contained in:
artem 2023-10-18 21:44:14 +03:00
parent f1ab7c2750
commit 6887247d8d
2 changed files with 46 additions and 47 deletions

View File

@ -1,32 +1,16 @@
import math
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import numexpr as ne
import openpyxl as op
from tkinter import ttk
from matplotlib.figure import Figure
class Graph:
def __init__(self,check_butt_cond,x, y,lab="f(x)",xl="x",yl="y",linetype='k',lims=False):
def __init__(self,x, y,labels,mult_subplots=0,xl="x",yl="y",linetype='k',lims=False):
#словарь из настроек?
self.labels=labels
self.__x=x
self.__y=y
self.__fig =Figure(figsize=(5,4),dpi=100)
self.__chb=check_butt_cond
self.__chb=mult_subplots
self.__ax=self.__fig.add_subplot()
#сделать отслеживание за состояние кнопок потом
"""
if self.__chb==0:
@ -36,9 +20,10 @@ class Graph:
axes=self.__fig.add_subplot(n)
axes.set_title(f"График №{i+1}")
c=axes.plot(self.__x[i],self.__y[i],label=lab,linestyle=linetype,)
c=axes.plot(self.__x[i],self.__y[i],label=lab)
else:
line=self.__ax.plot(self.__x,self.__y,label=lab,)
line=self.__ax.plot(self.__x[0],self.__y[0],label=lab,)
print(self.__x)
else:
if len(self.__x)>1: #много графиков на одном холсте
@ -48,48 +33,44 @@ class Graph:
else:
line=self.__ax.plot(self.__x,self.__y,label=lab,)
line=self.__ax.plot(self.__x[0],self.__y[0],label=lab,)
print(self.__x)
"""
self.draw_n_func_plot()
self.draw_one_func()
self.draw_subplots()
self.__ax.set_xlabel(xl)
self.__ax.set_ylabel(yl)
self.__ax.legend()
self.figure.tight_layout()
def add_vline( ax,x=0, ymin=0, ymax=1):
ax.axvline(x,ymin,ymax)
#принимаем плот и на нем же рисуем
def add_hline(ax,y=0, xmin=0, xmax=1,):
ax.axhline(y, xmin, xmax)
def draw_n_func_plot(self,): #много графиков на одном холсте
if self.__chb==1 and len(self.__x)>1:
for i in range(len(self.__x)):
self.__ax.plot(self.__x[i],self.__y[i])
def draw_one_func(self,lab="f(x)"):
if len(self.__x)==1:
self.__ax.plot(self.__x,self.__y,label=lab,)
def draw_subplots(self,lab="f(x)"):
if self.__chb==0 and len(self.__x)>1:
for i in range(len(self.__x)):
self.__ax.plot(self.__x[i],self.__y[i],label=self.labels[i])
def draw_one_func(self,):
if len(self.__x)==1:
self.__ax.plot(self.__x[0],self.__y[0],label=self.labels[0])#
def draw_subplots(self,):
if self.__chb==1 and len(self.__x)>1:
for i in range(len(self.__x)):
n=int(f"{len(self.__x)}1{i+1}")
axes=self.__fig.add_subplot(n)
axes.set_title(f"График №{i+1}")
axes.plot(self.__x[i],self.__y[i],label=lab,)
axes.plot(self.__x[i],self.__y[i],label=self.labels[i])
@property
def figure(self,):
return self.__fig
return self.__fig

View File

@ -1,5 +1,23 @@
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
import matplotlib
matplotlib.use('Qt5Agg')
import Graph
from PyQt5 import QtWidgets
class GraphWidget(FigureCanvasQTAgg):
def __init__(self, *args):
...
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
class GraphWidget(QtWidgets.QWidget):
def __init__(self, x, y, labels, mult_plots=False):
super().__init__()
graph = Graph.Graph(x,y,labels, mult_subplots=mult_plots)
sc = FigureCanvasQTAgg(graph.figure)
# Create toolbar, passing canvas as first parament, parent (self, the MainWindow) as second.
toolbar = NavigationToolbar(sc, self)
layout = QtWidgets.QVBoxLayout()
layout.addWidget(toolbar)
layout.addWidget(sc)
self.setLayout(layout)