From dba43e3748d80838821ce4ed0c0b91c04b56b5f1 Mon Sep 17 00:00:00 2001 From: Kefal Date: Wed, 18 Oct 2023 17:39:20 +0300 Subject: [PATCH] Created real graph builder and deleted example --- GraphWidget/Graph.py | 95 ++++++++++++++++++++++++++++++++++++ GraphWidget/Graph_example.py | 48 ------------------ 2 files changed, 95 insertions(+), 48 deletions(-) create mode 100644 GraphWidget/Graph.py delete mode 100644 GraphWidget/Graph_example.py diff --git a/GraphWidget/Graph.py b/GraphWidget/Graph.py new file mode 100644 index 0000000..769070e --- /dev/null +++ b/GraphWidget/Graph.py @@ -0,0 +1,95 @@ +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): + #словарь из настроек? + + + + self.__x=x + self.__y=y + self.__fig =Figure(figsize=(5,4),dpi=100) + self.__chb=check_butt_cond + self.__ax=self.__fig.add_subplot() + + + + + #сделать отслеживание за состояние кнопок потом + """ + if self.__chb==0: + if 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}") + c=axes.plot(self.__x[i],self.__y[i],label=lab,linestyle=linetype,) + else: + line=self.__ax.plot(self.__x,self.__y,label=lab,) + + else: + if len(self.__x)>1: #много графиков на одном холсте + for i in range(len(self.__x)): + self.__ax.plot(self.__x[i],self.__y[i]) + + + else: + + line=self.__ax.plot(self.__x,self.__y,label=lab,) + """ + self.draw_n_func_plot() + self.draw_one_func() + self.draw_subplots() + + + + self.__ax.set_xlabel(xl) + self.__ax.set_ylabel(yl) + + + 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)): + 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,) + @property + def figure(self,): + return self.__fig + + \ No newline at end of file diff --git a/GraphWidget/Graph_example.py b/GraphWidget/Graph_example.py deleted file mode 100644 index 82d833e..0000000 --- a/GraphWidget/Graph_example.py +++ /dev/null @@ -1,48 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt - -class GraphStatic: - @classmethod - def plot(cls, xs: np.ndarray, ys: np.ndarray, params: dict[str, str]) -> plt.Figure: - """ - строим график через - """ - ax, fig = plt.subplots(...) - - """" - Все методы при этом статичные - """ - - cls.__some_func(1, 2) - - """ - И возвращаем Figure - """ - - return fig - - @staticmethod - def __some_func(arg1, agr2): - ... - - -class GraphStatefull: - def __init__(self, xs: np.ndarray, ys: np.ndarray, params: dict[str, str]): - self.__xs = xs - self.__ys = ys - - self.__params = params - ax, fig = plt.subplots(...) - - self.__fig = fig - self.__ax = ax - - """ - строим график - """ - - def __some_func(self, arg1, arg2): - self.__ax.do_something(self.__params['something']) - - def get_fig(self) -> plt.Figure: - return self.__fig \ No newline at end of file