Fixed redundant axes on multi-subplots graphic, removed incorrect methods in Graph
This commit is contained in:
parent
7e5fe2beeb
commit
c64d32625b
@ -1,4 +1,5 @@
|
|||||||
from matplotlib.figure import Figure
|
from matplotlib.figure import Figure
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
class Graph:
|
class Graph:
|
||||||
@ -11,54 +12,43 @@ class Graph:
|
|||||||
self.__y = y
|
self.__y = y
|
||||||
self.__fig = Figure(figsize=(5, 4), dpi=100)
|
self.__fig = Figure(figsize=(5, 4), dpi=100)
|
||||||
self.__chb = mult_subplots
|
self.__chb = mult_subplots
|
||||||
self.__ax = self.__fig.add_subplot()
|
self.__xl = xl
|
||||||
|
self.__yl = yl
|
||||||
|
|
||||||
self.draw_n_func_plot()
|
self.draw_n_func_plot()
|
||||||
|
|
||||||
self.draw_subplots()
|
self.draw_subplots()
|
||||||
|
|
||||||
self.__ax.set_xlabel(xl)
|
|
||||||
self.__ax.set_ylabel(yl)
|
|
||||||
self.__ax.legend()
|
|
||||||
self.figure.tight_layout()
|
self.figure.tight_layout()
|
||||||
|
|
||||||
def add_vline(ax, x=0, ymin=0, ymax=1):
|
def add_ax_labels(
|
||||||
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,
|
self,
|
||||||
): # много графиков на одном холсте
|
ax: plt.Axes,
|
||||||
if self.__chb == 0 and len(self.__x) > 1:
|
):
|
||||||
|
ax.set_xlabel(self.__xl)
|
||||||
|
ax.set_ylabel(self.__yl)
|
||||||
|
|
||||||
|
def draw_n_func_plot(self): # много графиков на одном холсте
|
||||||
|
if self.__chb == 0 and len(self.__x) > 0:
|
||||||
|
self.__ax = self.__fig.add_subplot()
|
||||||
|
|
||||||
for i in range(len(self.__x)):
|
for i in range(len(self.__x)):
|
||||||
self.__ax.plot(self.__x[i], self.__y[i], label=self.labels[i])
|
self.__ax.plot(self.__x[i], self.__y[i], label=self.labels[i])
|
||||||
#новое(старое) условие против проскока
|
|
||||||
if self.__chb == 0 and len(self.__x) == 1:
|
|
||||||
self.__ax.plot(self.__x[0], self.__y[0], label=self.labels[0])
|
|
||||||
|
|
||||||
|
|
||||||
|
self.__ax.legend()
|
||||||
|
self.add_ax_labels(self.__ax)
|
||||||
|
|
||||||
def draw_subplots(
|
def draw_subplots(
|
||||||
self,
|
self,
|
||||||
):
|
):
|
||||||
if self.__chb == 1 and len(self.__x) > 1:
|
if self.__chb == 1 and len(self.__x) > 0:
|
||||||
for i in range(len(self.__x)):
|
for i in range(len(self.__x)):
|
||||||
n = int(f"{len(self.__x)}1{i+1}")
|
n = int(f"{len(self.__x)}1{i+1}") # Nx1 grid (column), i+1 subplot
|
||||||
|
|
||||||
axes = self.__fig.add_subplot(n)
|
axes = self.__fig.add_subplot(n)
|
||||||
axes.set_title(f"График №{i+1}")
|
axes.set_title(f"График №{i+1}")
|
||||||
axes.plot(self.__x[i], self.__y[i], label=self.labels[i])
|
axes.plot(self.__x[i], self.__y[i], label=self.labels[i])
|
||||||
#новое(старое) условие против проскока
|
self.add_ax_labels(axes)
|
||||||
if self.__chb ==1 and len(self.__x) == 1:
|
|
||||||
self.__ax.plot(self.__x[0], self.__y[0], label=self.labels[0])
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def figure(
|
def figure(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user