11
Июн
2021

Очень сильно тормозит анимация(2d) matplotlib с Pyqt5

Всем добрый день, добавляю gui для одной программы, программа сама без интерфейса нормально рисует, причем быстро, и можно крутить моделью после работы программывведите сюда описание изображения

а вот после добавления gui'а сама прорисовка стала очень медленной и просто невозможной для прокрутки моделивведите сюда описание изображения,

я скорее всего предполагаю из за всех глобалов которые я добавил в моем коде, но с моими знаниями(я новичок в python) это мой максимальный результат, пожалуйста помогите возможно ли, как то ускорить анимацию?


import sys

from PyQt5.QtWidgets import QApplication, QMainWindow, QMenu, QVBoxLayout, QSizePolicy, QLabel, QPushButton, QLineEdit, QMessageBox
from PyQt5.QtGui import QIcon, QValidator, QDoubleValidator


from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import numpy as np
import threading
import matplotlib.cm
from mpl_toolkits.mplot3d import Axes3D
from scipy.interpolate import griddata

import pylab
import time

#ky1 = 0.8
#ky2 = -80.0
#ky3 = 1.99
#ky4 = 0.3
#ky5 = 2.0

#kv1 = 1.9
#kv2 = -80.0
#kv3 = 1.8
#kv4 = 0.5
#kv5 = 2.0

N1 = 40
tt = 3.0
l = 2.
h = l/N1
N2 = 50
t=tt/N2
t2=t/2.0
hh=h*h
rr=hh/t

a11=0.03
a12=0.01
p1=-0.05
a21=0.03
a22=0.01
p2=-0.03
q1=0.0
q2=0.0

m1=0.95
m2=1.2
d1=0.7
d2=0.5
c1=0.25
c2=0.65
h1=0.55
b1=0.1
#x =np.zeros((N1+1), 'float')
#y =np.zeros((N1+1), 'float')
#v =np.zeros((N1+1), 'float')
#a =np.zeros((N1), 'float')
#b =np.zeros((N1), 'float')
#z =np.zeros((N1+1), 'float')

x1 = np.zeros((N1+1), 'float')
x2 = np.zeros((N1+1), 'float')
y = np.zeros((N1+1, N1+1), 'float')
y0 = np.zeros((N1+1, N1+1), 'float')
v = np.zeros((N1+1, N1+1), 'float')
v0 = np.zeros((N1+1, N1+1), 'float')
a = np.zeros((N1+1), 'float')
b = np.zeros((N1+1), 'float')
z = np.zeros((N1+1), 'float')
R = np.zeros((N1+1, N1+1), 'float')


class App(QMainWindow):

    def __init__(self):
        super().__init__()
        self.left = 10
        self.top = 10
        self.title = ''
        self.width = 1280
        self.height = 720
        self.initUI()

    def initVars(self):
        #global ky1
        #global ky2
        #global ky3
        #global ky4
        #global ky5
        #global kv1
        #global kv2
        #global kv3
        #global kv4
        #global kv5
        global N1
        global tt
        global l
        global h
        global N2
        global t
        global t2
        global hh
        global rr
        global a11
        global a12
        global p1
        global a21
        global a22
        global p2
        global q1
        global q2
        global m1
        global m2
        global d1
        global d2
        global c1
        global c2
        global h1
        global b1
        global x1
        global x2
        global y
        global y0 
        global v
        global v0 
        global a 
        global b 
        global z 
        global R 
        
        #ky1 = float(self.le_ky1.text())
        #ky2 = float(self.le_ky2.text())
        #ky3 = float(self.le_ky3.text())
        #ky4 = float(self.le_ky4.text())
        #ky5 = float(self.le_ky5.text())
        #kv1 = float(self.le_kv1.text())
        #kv2 = float(self.le_kv2.text())
        #kv3 = float(self.le_kv3.text())
        #kv4 = float(self.le_kv4.text())
        #kv5 = float(self.le_kv5.text())
        N1  = int(self.le_N1 .text())
        tt  = float(self.le_tt .text())
        l   = float(self.le_l  .text())
        N2  = int(self.le_N2 .text())
        a11 = float(self.le_a11.text())
        a12 = float(self.le_a12.text())
        p1  = float(self.le_p1 .text())
        a21 = float(self.le_a21.text())
        a22 = float(self.le_a22.text())
        p2  = float(self.le_p2 .text())
        q1  = float(self.le_q1 .text())
        q2  = float(self.le_q2 .text())
        m1  = float(self.le_m1 .text())
        m2  = float(self.le_m2 .text())
        d1  = float(self.le_d1 .text())
        d2  = float(self.le_d2 .text())
        c1  = float(self.le_c1 .text())
        c2  = float(self.le_c2 .text())
        h1  = float(self.le_h1 .text())
        b1  = float(self.le_b1 .text())

        #if kv4 > 2 or kv4 < 0:
        #    QMessageBox.about(self, "Ошибка", "Значение kv4 должно быть от 0 до 2")
        #else:
        h = l/N1
        t=tt/N2
        t2=t/2.0
        hh=h*h
        rr=hh/t
        
        x1 = np.zeros((N1+1), 'float')
        x2 = np.zeros((N1+1), 'float')
        y = np.zeros((N1+1, N1+1), 'float')
        y0 = np.zeros((N1+1, N1+1), 'float')
        v = np.zeros((N1+1, N1+1), 'float')
        v0 = np.zeros((N1+1, N1+1), 'float')
        a = np.zeros((N1+1), 'float')
        b = np.zeros((N1+1), 'float')
        z = np.zeros((N1+1), 'float')
        R = np.zeros((N1+1, N1+1), 'float')
        self.m.plot()


    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        self.m = PlotCanvas(self, width=8, height=6)
        self.m.move(0,0)
        
        
        y = 0
        #label = QLabel('ky1:', self)
        #label.move(850, y)
        #label.resize(50, 20)
        #y += 20
        #label = QLabel('ky2:', self)
        #label.move(850, y)
        #label.resize(50, 20)
        #y += 20
        #label = QLabel('ky3:', self)
        #label.move(850, y)
        #label.resize(50, 20)
        #y += 20
        #label = QLabel('ky4:', self)
        #label.move(850, y)
        #label.resize(50, 20)
        #y += 20
        #label = QLabel('ky5:', self)
        #label.move(850, y)
        #label.resize(50, 20)
        #y += 20
        #label = QLabel('kv1:', self)
        #label.move(850, y)
        #label.resize(50, 20)
        #y += 20
        #label = QLabel('kv2:', self)
        #label.move(850, y)
        #label.resize(50, 20)
        #y += 20
        #label = QLabel('kv3:', self)
        #label.move(850, y)
        #label.resize(50, 20)
        #y += 20
        #label = QLabel('kv4:', self)
        #label.move(850, y)
        #label.resize(50, 20)
        #y += 20
        #label = QLabel('kv5:', self)
        #label.move(850, y)
        #label.resize(50, 20)
        #y += 20
        label = QLabel('N1:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('tt:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('l:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('N2:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('a11:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('a12:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('p1:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('a21:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('a22:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('p2:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('q1:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('q2:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('m1:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('m2:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('d1:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('d2:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('c1:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('c2:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('h1:', self)
        label.move(850, y)
        label.resize(50, 20)
        y += 20
        label = QLabel('b1:', self)
        label.move(850, y)
        label.resize(50, 20)
        y = 0
        
        
        #self.le_ky1  = QLineEdit('0.8', self)
        #self.le_ky1.move(890, y)
        #self.le_ky1.resize(50, 20)
        #y += 20
        #self.le_ky2  = QLineEdit('-80.0', self)
        #self.le_ky2.move(890, y)
        #self.le_ky2.resize(50, 20)
        #y += 20
        #self.le_ky3  = QLineEdit('1.99', self)
        #self.le_ky3.move(890, y)
        #self.le_ky3.resize(50, 20)
        #y += 20
        #self.le_ky4  = QLineEdit('0.3', self)
        #self.le_ky4.move(890, y)
        #self.le_ky4.resize(50, 20)
        #y += 20
        #self.le_ky5  = QLineEdit('2.0', self)
        #self.le_ky5.move(890, y)
        #self.le_ky5.resize(50, 20)
        #y += 20
        #self.le_kv1  = QLineEdit('1.9', self)
        #self.le_kv1.move(890, y)
        #self.le_kv1.resize(50, 20)
        #y += 20
        #self.le_kv2  = QLineEdit('-80.0', self)
        #self.le_kv2.move(890, y)
        #self.le_kv2.resize(50, 20)
        #y += 20
        #self.le_kv3  = QLineEdit('1.8', self)
        #self.le_kv3.move(890, y)
        #self.le_kv3.resize(50, 20)
        #y += 20
        #self.le_kv4  = QLineEdit('0.5', self)
        #self.le_kv4.move(890, y)
        #self.le_kv4.resize(50, 20)
        #y += 20
        #self.le_kv5  = QLineEdit('2.0', self)
        #self.le_kv5.move(890, y)
        #self.le_kv5.resize(50, 20)
        #y += 20
        self.le_N1  = QLineEdit('40', self)
        self.le_N1.move(890, y)
        self.le_N1.resize(50, 20)
        y += 20
        self.le_tt  = QLineEdit('3.0', self)
        self.le_tt.move(890, y)
        self.le_tt.resize(50, 20)
        y += 20
        self.le_l  = QLineEdit('2',self)
        self.le_l.move(890, y)
        self.le_l.resize(50, 20)
        y += 20
        self.le_N2  = QLineEdit('50',self)
        self.le_N2.move(890, y)
        self.le_N2.resize(50, 20)
        y += 20
        self.le_a11 = QLineEdit('0.03',self)
        self.le_a11.move(890, y)
        self.le_a11.resize(50, 20)
        y += 20
        self.le_a12 = QLineEdit('0.01',self)
        self.le_a12.move(890, y)
        self.le_a12.resize(50, 20)
        y += 20
        self.le_p1  = QLineEdit('0.05',self)
        self.le_p1.move(890, y)
        self.le_p1.resize(50, 20)
        y += 20
        self.le_a21 = QLineEdit('0.03',self)
        self.le_a21.move(890, y)
        self.le_a21.resize(50, 20)
        y += 20
        self.le_a22 = QLineEdit('0.01',self)
        self.le_a22.move(890, y)
        self.le_a22.resize(50, 20)
        y += 20
        self.le_p2  = QLineEdit('0.03',self)
        self.le_p2.move(890, y)
        self.le_p2.resize(50, 20)
        y += 20
        self.le_q1  = QLineEdit('0.00',self)
        self.le_q1.move(890, y)
        self.le_q1.resize(50, 20)
        y += 20
        self.le_q2  = QLineEdit('0.00',self)
        self.le_q2.move(890, y)
        self.le_q2.resize(50, 20)
        y += 20
        self.le_m1  = QLineEdit('0.95',self)
        self.le_m1.move(890, y)
        self.le_m1.resize(50, 20)
        y += 20
        self.le_m2  = QLineEdit('1.2',self)
        self.le_m2.move(890, y)
        self.le_m2.resize(50, 20)
        y += 20
        self.le_d1  = QLineEdit('0.7',self)
        self.le_d1.move(890, y)
        self.le_d1.resize(50, 20)
        y += 20
        self.le_d2  = QLineEdit('0.5',self)
        self.le_d2.move(890, y)
        self.le_d2.resize(50, 20)
        y += 20
        self.le_c1  = QLineEdit('0.25',self)
        self.le_c1.move(890, y)
        self.le_c1.resize(50, 20)
        y += 20
        self.le_c2  = QLineEdit('0.65',self)
        self.le_c2.move(890, y)
        self.le_c2.resize(50, 20)
        y += 20
        self.le_h1  = QLineEdit('0.55',self)
        self.le_h1.move(890, y)
        self.le_h1.resize(50, 20)
        y += 20
        self.le_b1  = QLineEdit('0.1',self)
        self.le_b1.move(890, y)
        self.le_b1.resize(50, 20)
        y += 20

        
        button = QPushButton('Start', self)
        button.move(840,y)
        button.resize(50,25)
        button.clicked.connect(self.initVars)

        self.show()


class PlotCanvas(FigureCanvas):

    def e1(self,u,v):
        return a11+a12*u*v

    def e2(self,u,v):
        return a21+a22*u*v

    def f1(self,u,v):
        return u*(m1-d1)+v*d1-c1*u*u-h1*u-b1
    def f2(self,u,v):
        return v*(m2-d2)+u*d2-c2*v*v

    def Rs(self, x, y):
        return 4
        #2 zone
        #return 0.5*np.sin(3*np.pi*x/2.)+0.5*np.sin(np.pi*x/3.)+np.sin(np.pi*x/2.)
        #return 1.5*np.sin(np.pi*x/2.)+0.5*np.sin(1*np.pi*x/2.)*np.sin(2.*np.pi*x/1.)
        #return 1.2 * np.sin(3 * np.pi * x / 2.) + 0.5 * np.sin(np.pi * x / 3.) * np.sin(np.pi * x / 2.)
        #1 zone
        #return 0.5*np.sin(3*np.pi*x/2.)-0.2*np.sin(2*np.pi*x/2.)-np.sin(3.*np.pi*x/3.)
        #return 1.5*np.sin(np.pi*x/2.)-0.5*np.sin(1*np.pi*x/2.)*np.sin(2.*np.pi*x/2.)

        

    def y_0(self, x,y):
        return 1.5 * np.exp(-20.0*(((x/2.0)-0.5)**2 + (y-0.5)**2))
    def v_0(self, x,y):
        return 1.5 * np.exp(-20.0*(((x/2.0)-0.5)**2 + (y-1.5)**2))

    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,
                QSizePolicy.Expanding,
                QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self)
        

        
    def plot(self):
        self.axes.cla()
        plt = self.figure.add_subplot(111)
        global N1
        global tt
        global l
        global h
        global N2
        global t
        global t2
        global hh
        global rr
        global a11
        global a12
        global p1
        global a21
        global a22
        global p2
        global q1
        global q2
        global m1
        global m2
        global d1
        global d2
        global c1
        global c2
        global h1
        global b1
        global x1 
        global x2 
        global y
        global y0 
        global v
        global v0 
        global a 
        global b 
        global z 
        global R 
        
        tst = time.perf_counter()
        for i1 in range(0,N1+1):
            x1[i1]=i1*h
        for i2 in range(0,N1+1):
            x2[i2]=i2*h
        for i1 in range(0, N1+1):
            for i2 in range(0, N1+1):
                y0[i1, i2] = self.y_0(x1[i1], x2[i2])
                v0[i1, i2] = self.v_0(x1[i1], x2[i2])
                R[i1, i2] = self.Rs(x1[i1], x2[i2])
                y[i1, i2] = y0[i1, i2]
                v[i1, i2] = v0[i1, i2]
                
        x1 = np.linspace(0., l, N1+1)
        x2 = np.linspace(0., l, N1+1)
        X1,X2 = np.meshgrid(x1, x2)
        
        plt.set_xlabel('X')
        plt.set_ylabel('Y')

        g = np.linspace(0., 2., 21)
        cmap1 = matplotlib.cm.get_cmap('Blues')
        cmap2 = matplotlib.cm.get_cmap('BuGn')
        plt.clabel(plt.contour(x1,x2,y0,g,colors='gray'), inline=True, fontsize=8)
        plt.contourf(x1,x2,y0,g,cmap=cmap1)
        plt.clabel(plt.contour(x1,x2,v0,g,colors='gray'), inline=True, fontsize=8)
        contourf_ = plt.contourf(x1,x2,v0,g,cmap=cmap2)
        self.figure.colorbar(contourf_)
        self.draw()

        for j in range(1,N2+1):

        # y[k+1/2] to x1
            for i2 in range(0,N1+1):
                #a[0]=0.
                #b[0]=0.
                e210 = self.e1((y[1,i2]+y[0,i2])/2.00,(v[1,i2]+v[0,i2])/2.00)
                a[0] = e210/(e210+rr/2.0)
                FD0 = (-p1/rr)*(y[1,i2]+y[0,i2])*(v[1,i2]-v[0,i2])- \
                      (q1/rr)*(y[1,i2]+y[0,i2])*(R[1,i2]-R[0,i2])+self.f1(y[0,i2],v[0,i2])*t2
                b[0] = (y[0,i2]+FD0)/(1+2.0*e210/rr)

                for i1 in range(1,N1):
                    e11 = self.e1((y[i1,i2]+y[i1-1,i2])/2.00,(v[i1,i2]+v[i1-1,i2])/2.00)
                    e12 = self.e1((y[i1,i2]+y[i1+1,i2])/2.00,(v[i1,i2]+v[i1+1,i2])/2.00)
                    aa = e11/rr
                    bb = e12/rr
                    cc = aa+bb+1
                    a[i1] = bb/(cc-aa*a[i1-1])

                    r11 = (1.0/rr)*(y[i1,i2]+y[i1-1,i2])/2.00
                    r12 = (1.0/rr)*(y[i1,i2]+y[i1+1,i2])/2.00

                    L1v = p1*(r12*(v[i1+1,i2]-v[i1,i2]) - r11*(v[i1,i2]-v[i1-1,i2]))
                    L1R = q1*(r12*(R[i1+1,i2]-R[i1,i2]) - r11*(R[i1,i2]-R[i1-1,i2]))

                    d = y[i1,i2] + self.f1(y[i1,i2],v[i1,i2])*t2 - L1v - L1R
                    b[i1]=(aa*b[i1-1]+d)/(cc-aa*a[i1-1])
                #y[N1,i2]=b[N1-1]/(1-a[N1-1])
                #y[N1,i2]=0.
                e22n = self.e1((y[N1,i2]+y[N1-1,i2])/2.00,(v[N1,i2]+v[N1-1,i2])/2.00)
                FDn = p1*(y[N1,i2]+y[N1-1,i2])*(v[N1,i2]-v[N1-1,i2])/2.0 + \
                      q1*(y[N1,i2]+y[N1-1,i2])*(R[N1,i2]-R[N1-1,i2])/2.0 + \
                      self.f1(y[N1,i2],v[N1,i2])*hh/4.0
                y[N1,i2]=(e22n*b[N1-1] + rr*y[N1,i2]/2.0 + FDn)/(e22n*(1-a[N1-1])+rr/2.0)
                for ii in range(1,N1+1):
                    i1=N1-ii
                    y[i1,i2] = a[i1]*y[i1+1,i2]+b[i1]

        # v[k+1/2] to x1
                e210 = self.e1((y[1,i2]+y[0,i2])/2.00,(v[1,i2]+v[0,i2])/2.00)
                a[0] = e210/(e210+rr/2.0)
                FD0 = (-p2/rr)*(v[1,i2]+v[0,i2])*(y[1,i2]-y[0,i2])- \
                      (q2/rr)*(v[1,i2]+v[0,i2])*(R[1,i2]-R[0,i2])+self.f2(y[0,i2],v[0,i2])*t2
                b[0] = (v[0,i2]+FD0)/(1+2.0*e210/rr)
                for i1 in range(1,N1):
                    e21=self.e2((y[i1,i2]+y[i1-1,i2])/2.00,(v[i1,i2]+v[i1-1,i2])/2.00)
                    e22=self.e2((y[i1,i2]+y[i1+1,i2])/2.00,(v[i1,i2]+v[i1+1,i2])/2.00)
                    aa = e21/rr
                    bb = e22/rr
                    cc = aa+bb+1
                    a[i1] = bb/(cc-aa*a[i1-1])

                    r11 = (1.0/rr)*(v[i1,i2]+v[i1-1,i2])/2.
                    r12 = (1.0/rr)*(v[i1,i2]+v[i1+1,i2])/2.

                    L1y = p2*(r12*(y[i1+1,i2]-y[i1,i2]) - r11*(y[i1,i2]-y[i1-1,i2]))
                    L1R = q2*(r12*(R[i1+1,i2]-R[i1,i2]) - r11*(R[i1,i2]-R[i1-1,i2]))

                    d = v[i1,i2] + self.f2(y[i1,i2],v[i1,i2])*t2 - L1y - L1R
                    b[i1]=(aa*b[i1-1]+d)/(cc-aa*a[i1-1])
                #v[N1,i2]=b[N1-1]/(1-a[N1-1])
                #v[N1,i2]=0.
                e22n = self.e2((y[N1,i2]+y[N1-1,i2])/2.00,(v[N1,i2]+v[N1-1,i2])/2.00)
                FDn = p2*(v[N1,i2]+v[N1-1,i2])*(y[N1,i2]-y[N1-1,i2])/2.0 + \
                      q2*(v[N1,i2]+v[N1-1,i2])*(R[N1,i2]-R[N1-1,i2])/2.0 + \
                      self.f2(y[N1,i2],v[N1,i2])*hh/4.0
                v[N1,i2]=(e22n*b[N1-1] + rr*v[N1,i2]/2.0 + FDn)/(e22n*(1-a[N1-1])+rr/2.0)

                for ii in range(1,N1+1):
                    i1=N1-ii
                    v[i1,i2] = a[i1]*v[i1+1,i2]+b[i1]

        # y[k+1] to x2
            for i1 in range(0,N1+1):
                a[0]=0.
                b[0]=0.
                #e210 = e1((y[i1,1]+y[i1,0])/2.00,(v[i1,1]+v[i1,0])/2.00)
                #FD0 = (-p1/rr)*(y[i1,1]+y[i1,0])*(v[i1,1]-v[i1,0])- \
                #      (q1/rr)*(y[i1,1]+y[i1,0])*(R[i1,1]-R[i1,0])+f1(y[i1,0],v[i1,0])*t2
                #b[0] = (y[i1,0]+FD0)/(1+2.0*e210/rr)

                for i2 in range(1,N1):
                    e21 = self.e1((y[i1,i2]+y[i1,i2-1])/2.00,(v[i1,i2]+v[i1,i2-1])/2.00)
                    e22 = self.e1((y[i1,i2]+y[i1,i2+1])/2.00,(v[i1,i2]+v[i1,i2+1])/2.00)
                    aa = e21/rr
                    bb = e22/rr
                    cc = aa+bb+1
                    a[i2] = bb/(cc-aa*a[i2-1])

                    r21 = (1.0/rr)*(y[i1,i2]+y[i1,i2-1])/2.
                    r22 = (1.0/rr)*(y[i1,i2]+y[i1,i2+1])/2.

                    L2v = p1*(r22*(v[i1,i2+1]-v[i1,i2]) - r21*(v[i1,i2]-v[i1,i2-1]))
                    L2R = q1*(r22*(R[i1,i2+1]-R[i1,i2]) - r21*(R[i1,i2]-R[i1,i2-1]))

                    d = y[i1,i2] + self.f1(y[i1,i2],v[i1,i2])*t2 - L2v - L2R
                    b[i2]=(aa*b[i2-1]+d)/(cc-aa*a[i2-1])
                y[i1,N1]=0.
                #e22n = e1((y[i1,N1]+y[i1,N1-1])/2.00,(v[i1,N1]+v[i1,N1-1])/2.00)
                #FDn = p1*(y[i1,N1]+y[i1,N1-1])*(v[i1,N1]-v[i1,N1-1])/2.0 + \
                #      q1*(y[i1,N1]+y[i1,N1-1])*(R[i1,N1]-R[i1,N1-1])/2.0 + \
                #      f1(y[i1,N1],v[i1,N1])*hh/4.0
                #y[i1,N1]=(e22n*b[N1-1] + rr*y[i1,N1]/2.0 + FDn)/(e22n*(1-a[N1-1])+rr/2.0)

                for ii in range(1,N1+1):
                    i2=N1-ii
                    y[i1,i2] = a[i2]*y[i1,i2+1]+b[i2]

                for i2 in range(0,N1+1):
                    if y[i1,i2]<0: y[i1,i2]=0.0

        # v[k+1] to x2
                #e210 = e2((y[i1,1]+y[i1,0])/2.00,(v[i1,1]+v[i1,0])/2.00)
                #a[0] = e210/(e210+rr/2.0)
                #FD0 = (-p2/rr)*(v[i1,1]+v[i1,0])*(y[i1,1]-y[i1,0])- \
                #      (q2/rr)*(v[i1,1]+v[i1,0])*(R[i1,1]-R[i1,0])+f2(y[i1,0],v[i1,0])*t2
                #b[0] = (v[i1,0]+FD0)/(1+2.0*e210/rr)

                for i2 in range(1,N1):
                    e21=self.e2((y[i1,i2]+y[i1,i2-1])/2.00,(v[i1,i2]+v[i1,i2-1])/2.00)
                    e22=self.e2((y[i1,i2]+y[i1,i2+1])/2.00,(v[i1,i2]+v[i1,i2+1])/2.00)
                    aa = e21/rr
                    bb = e22/rr
                    cc = aa+bb+1
                    a[i2] = bb/(cc-aa*a[i2-1])

                    r21 = (1.0/rr)*(v[i1,i2]+v[i1,i2-1])/2.
                    r22 = (1.0/rr)*(v[i1,i2]+v[i1,i2+1])/2.

                    L2y = p2*(r22*(y[i1,i2+1]-y[i1,i2])-r21*(y[i1,i2]-y[i1,i2-1]))
                    L2R = q2*(r22*(R[i1,i2+1]-R[i1,i2])-r21*(R[i1,i2]-R[i1,i2-1]))

                    d = v[i1,i2] + self.f2(y[i1,i2],v[i1,i2])*t2 - L2y - L2R
                    b[i2]=(aa*b[i2-1]+d)/(cc-aa*a[i2-1])
                v[i1,N1]=0.
                #e22n = e2((y[i1,N1]+y[i1,N1-1])/2.00,(v[i1,N1]+v[i1,N1-1])/2.00)
                #FDn = p2*(v[i1,N1]+v[i1,N1-1])*(y[i1,N1]-y[i1,N1-1])/2.0 + \
                #      q2*(v[i1,N1]+v[i1,N1-1])*(R[i1,N1]-R[i1,N1-1])/2.0 + \
                #      f2(y[i1,N1],v[i1,N1])*hh/4.0
                #v[i1,N1]=(e22n*b[N1-1] + rr*v[i1,N1]/2.0 + FDn)/(e22n*(1-a[N1-1])+rr/2.0)

                for ii in range(1,N1+1):
                    i2=N1-ii
                    v[i1,i2] = a[i2]*v[i1,i2+1]+b[i2]

                for i2 in range(0,N1+1):
                    if v[i1,i2]<0: v[i1,i2]=0.0
        #graphics
            pylab.clf()
            x1 = np.linspace(0., l, N1+1)
            x2 = np.linspace(0., l, N1+1)
            #fig = plt.figure()
            ax = Axes3D(plt.figure)
            X1, X2 = np.meshgrid(x1, x2)
            plt.set_xlabel('X')
            plt.set_ylabel('Y')
            ax.plot_surface(X1, X2, y, rstride=1, cstride=1, cmap='Blues')
            ax.plot_surface(X1, X2, v, rstride=1, cstride=1, cmap='BuGn')
            ax.plot_wireframe(X1, X2, y, rstride=1, cstride=1)
            
            app.processEvents()   
            self.draw()

        ax = Axes3D(plt.figure)
        x1 = np.linspace(0., l, N1+1)
        x2 = np.linspace(0., l, N1+1)
        X1,X2 = np.meshgrid(x1, x2)
        plt.set_xlabel('X')
        plt.set_ylabel('Y')
        ax.plot_surface(X1, X2, y, rstride=1, cstride=1, cmap='Blues')
        ax.plot_surface(X1, X2, v, rstride=1, cstride=1, cmap='BuGn')
        ax.plot_wireframe(X1, X2, y, rstride=1, cstride=1)
        self.draw()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())


Источник: https://ru.stackoverflow.com/questions/1294293/%D0%9E%D1%87%D0%B5%D0%BD%D1%8C-%D1%81%D0%B8%D0%BB%D1%8C%D0%BD%D0%BE-%D1%82%D0%BE%D1%80%D0%BC%D0%BE%D0%B7%D0%B8%D1%82-%D0%B0%D0%BD%D0%B8%D0%BC%D0%B0%D1%86%D0%B8%D1%8F2d-matplotlib-%D1%81-pyqt5

Тебе может это понравится...

Добавить комментарий