Python动态建模4

上一篇:

Python动态建模-(3)_Unconquerable&Llxy的博客-CSDN博客modefunc:函数(就是上面定义的write()._write_t、write()._write_t_x、write()._write_t_y、write()._write_t_z四选一)bool布尔值(True、False)------------默认为True,真。...https://blog.csdn.net/html_finder/article/details/126161824

感谢以下文章和资料作为参考:

用 Matplotlib 库生成动画图表 - UCloud云社区动画是一种展示现象的有趣方式。相对于静态图表,人类总是容易被动画和交互式图表所吸引。在描述多年来的股票价格、过去十年的气候变化、季节性和趋势等时间序列数据时,动画更有意义,因为我们可以看到特定的参...https://www.ucloud.cn/yun/43671.htmlvideo - FFMPEG No such filter: 'palettegen' - Stack Overflowhttps://stackoverflow.com/questions/34134854/ffmpeg-no-such-filter-palettegenhttps://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonmagickhttps://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonmagick【Python】图片处理之“PythonMagick”库简易安装笔记_蛙鳜鸡鹳狸猿的博客-CSDN博客_pythonmagick“ImageMagick”可以说是开源的代码/命令行版PS,它支持包括创建、编辑、构图再到格式转换的图片处理功能。更重要的是,它几乎完整支持大部分编程语言,其中Python的接口库就是“PythonMagick”了。具体参考http://www.imagemagick.org/script/index.php。以下整理了“PythonMagick”库在各操作环境的简易安装方法。①RPM式https://blog.csdn.net/sweeper_freedoman/article/details/52994690【Python】批量直接修改图片存储大小脚本_蛙鳜鸡鹳狸猿的博客-CSDN博客对图片的处理有的情况下是对存储大小而非纵横的“width&height”有要求,这种对图片文件磁盘存储大小修改的工作也往往是批量的。借助Python通过“PythonMagick”库(参考:http://blog.csdn.net/sweeper_freedoman/article/details/52994690)可以实现需求。脚本简单如下。# !/usr/bin/python#https://blog.csdn.net/sweeper_freedoman/article/details/53000520Python调用“ImageMagick”:图片格式转换、尺寸修改、属性重构及加水印_蛙鳜鸡鹳狸猿的博客-CSDN博客      “ImageMagick”的Python库是“PythonMagick”,如之前的博文(http://blog.csdn.net/sweeper_freedoman/article/details/53000520,http://blog.csdn.net/sweeper_freedoman/article/details/53000145),有借用“PythonMagick”写过...https://blog.csdn.net/sweeper_freedoman/article/details/69789307

现在明白了:缺少animation.save函数,并且在调用ImageMagick和ffmpeg库(matplotlib依赖)时出错。

让我们解决一下...

1)关于上次报的Warning:

使用animation.save函数保存动态图表。

所以马上就能解决了

问题非常多,而且难以解决。

至此为止,我们的项目结束了破产了

这是完整的代码,其实基本功能都已经实现,关键在导出为图表的部分。各位大神可以以此为基础改进完善。

# coding=utf-8

__author__ = "Unconquerable&Llxy"
__name__ = "3DGraphic_With_Formula"

import sympy
from tkinter.messagebox import *
from tkinter import *
from math import *

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation


def no_ans():
    Tk().geometry("9x9+990000+999999")
    showerror("警告", "方程无解析解")


x = []
y = []
z = []
t = []


def toLeg(fx):
    v = str(fx).split("\n")
    val = []
    for i in v:
        tv = i.split("=")
        length = len(tv)
        last = None
        while length != 0:
            if length == 2:
                val.append('='.join(tv))
                break
            if length == 1:
                val.append('='.join([tv[0], str(last)]))
                break
            val.append('='.join([tv[-2], tv[-1]]))
            length = length - 1
            last = tv[-1]
            tv.pop()
    return '\n'.join(val)


def legalSet(fx):
    v = str(fx).split("\n")
    nw = []
    for l in v:

        tmpstr = ""
        tmpstr2 = ""
        if l == '': continue
        k = l.split("=")
        tmpstr += "((" + k[0] + ")-(" + k[1] + "))"
        tmpstr2 += "((" + k[1] + ")-(" + k[0] + "))"
        tmpstrs = [tmpstr, tmpstr2]
        nw.append(tmpstrs)
    v = nw
    del nw

    index = -1
    for i in v:
        index += 1
        for j in range(2):
            if ":" in i: v[index][j] = i[j].replace(":", "/")
            if "^" in i: v[index][j] = i[j].replace("^", "**")
            if "÷" in i: v[index][j] = i[j].replace("÷", "/")
            if "×" in i: v[index][j] = i[j].replace("×", "*")
            if "[" in i: v[index][j] = i[j].replace("[", "(")
            if "]" in i: v[index][j] = i[j].replace("]", ")")
            if "【" in i: v[index][j] = i[j].replace("【", "(")
            if "】" in i: v[index][j] = i[j].replace("】", ")")
            if "{" in i: v[index][j] = i[j].replace("{", "(")
            if "}" in i: v[index][j] = i[j].replace("}", ")")
            if "(" in i: v[index][j] = i[j].replace("(", "(")
            if ")" in i: v[index][j] = i[j].replace(")", ")")
    newlt = []
    lt = []
    for j in v:

        lt__ = []

        news = []
        for i_ in j:
            new = ""
            pos = -1

            funcs = []
            for i in i_:

                pos += 1
                tmpos = pos + 0
                string = ""
                while i_[tmpos].isalpha():
                    string += i_[tmpos]
                    tmpos = tmpos + 1

                if string in sympy.__all__:
                    funcs += [i for i in range(pos, tmpos + 1)]

                if ((i.isalpha() or i == "(") and (i_[pos - 1].isnumeric() or i_[pos - 1].isalpha())
                        and pos != 0 and pos not in funcs):
                    new += "*" + " " + i

                else:

                    if (i.isalpha() and pos not in funcs):
                        new += " " + i
                    else:
                        new += i
                if i.isalpha() and pos not in funcs:
                    lt__.append(i)

            news.append(new)

        lt__ = list(set(lt__))
        lt.append(lt__)
        newlt.append(news)
    return newlt, lt


def sqrt(base, times=2):
    if base < 0:
        ans = (-base) ** (1 / times)
        return eval(f"{ans}j")
    return base ** (1 / times)


class write:
    def _write_t_x(self, formula, tmin_=-10, tmax_=10, tnums=100,
                   min_=-10, max_=10, nums=100, printout=True):

        global x, y, z, t

        self.step = (tmax_ - tmin_) / tnums
        self.aa = tmin_ - self.step
        self.xstep = (max_ - min_) / nums
        r"""

        print(un)
        print(lf,toLeg(formula),sep="\n\n",end="\n\n")
        """
        solves = []
        for iVal in range(tnums + 1):

            self.aa = self.aa + self.step
            self.aa = float("%.10f" % self.aa)
            xValue = min_ - self.xstep
            for XVAL in range(nums + 1):
                lf, un = legalSet(toLeg(formula))
                xValue += self.xstep
                xValue = float("%.10f" % xValue)

                def key(item):
                    if "t" in item[0] or "x" in item[0]:
                        return 1
                    else:
                        return 999

                bf = dict(enumerate(lf))
                lf = sorted(lf, key=key)
                nun = []
                for i in range(len(lf)):
                    nun.insert(lf.index(bf[i]), un[i])
                un = nun
                del nun
                idx = -1
                for imp in un:
                    idx += 1
                    for __imp in imp:
                        if __imp == 't':
                            un[idx].remove("t")
                        if __imp == 'x':
                            un[idx].remove("x")
                del idx

                repl = {"t": [str(self.aa)], "x": [str(xValue)]}
                is_exit = False
                times = -1
                while not is_exit:
                    times += 1

                    if times >= 10:
                        # print(f"\nmessage:目前已经循环求解超过10次,目前初始代入值为:x{repl['x']},t{repl['t']},\n"
                        #      f"已经求解{repl},剩{4-len(repl.values())}值不可求解,故不予求解并跳出循环")
                        break
                    indx = -1
                    for lf_ in lf:
                        indx += 1
                        for i in repl.keys():
                            for j in range(2):
                                lf_[j] = lf_[j].replace(" " + i, str(repl[i][0]))

                        idx = -1
                        for imp in un:
                            idx += 1
                            for __imp in imp:
                                if __imp in repl.keys():
                                    un[idx].remove(__imp)
                        del idx

                        if un[indx] == []:
                            del un[indx]
                            del lf[indx]
                            if indx == 0 or (indx - 1) >= len(lf): break
                            indx -= 1
                            continue

                        try:
                            ams = sympy.solve(tuple(lf_), tuple(un[indx]))
                            if ams == []:
                                newlf = []
                                for i in lf_:
                                    newlf.append(i.replace(str(repl["x"]), str(repl["x"]) + "*sympy.I"))
                                ams = sympy.solve(tuple(newlf), tuple(un[indx]))
                        except NotImplementedError as err:
                            print(err)
                            no_ans()
                            return

                        if isinstance(ams, (dict,)):
                            for km, jj in ams.items():
                                if not ('x' in str(jj) or
                                        'y' in str(jj) or
                                        'z' in str(jj) or
                                        't' in str(jj)):
                                    if km.name in repl.keys():
                                        repl[km.name].append(str(jj))
                                    else:
                                        repl[km.name] = [str(jj)]
                        else:
                            ix = -1
                            undo = 0
                            for i in ams:
                                ix += 1
                                try:
                                    if isinstance(i, (sympy.core.numbers.Float,
                                                      sympy.core.numbers.Integer,
                                                      int, float, complex)):

                                        try:
                                            repl[tuple(un[indx])[ix]] = [str(eval(str(i)))]
                                        except IndexError:

                                            repl[tuple(un[indx])[undo]].append(str(eval(str(i))))
                                        for i in repl.keys():
                                            if i in lf_:
                                                lf_ = lf_.replace(i, str(repl[i][0]))
                                    elif isinstance(i, (tuple, list, set)):
                                        inxx = -1
                                        for jj in i:
                                            inxx += 1
                                            if not ('x' in str(jj) or
                                                    'y' in str(jj) or
                                                    'z' in str(jj) or
                                                    't' in str(jj)):
                                                try:
                                                    repl[tuple(un[indx][inxx])[ix]] = [str(jj)]
                                                except IndexError:
                                                    repl[tuple(un[indx][inxx])[undo]].append(str(jj))
                                    else:
                                        continue
                                except TypeError as err:
                                    print("get:err", err)
                                    continue
                                else:
                                    undo = ix
                        if len(repl.values()) >= 4: is_exit = True;break
                if is_exit:
                    solves.append(repl)
                if printout:
                    print(f"\r{(iVal * (nums + 1) + XVAL + 1) / ((nums + 1) * (tnums + 1)) * 100}%", end="",
                          flush=True)

        if printout:
            print("\nsucceed in Calculating Values...")
        num = 0
        for i in solves:
            if printout:
                print(f"\r{(num + 1) / len(solves) * 100}%", end="", flush=True)
            num += 1
            x_ = []
            for j in i["x"]:
                x_.append(eval(j))
            x.append(x_)
            y_ = []
            for j in i["y"]:
                y_.append(eval(j))
            y.append(y_)
            z_ = []
            for j in i["z"]:
                z_.append(eval(j))
            z.append(z_)
            t_ = []
            for j in i["t"]:
                t_.append(eval(j))
            t.append(t_)

        del x_, y_, z_, t_, solves

        if printout:
            print("\nsucceed in Saving Values...")

    def _write_t_y(self, formula, tmin_=-10, tmax_=10, tnums=100,
                   min_=-10, max_=10, nums=100, printout=True):

        global x, y, z, t

        self.step = (tmax_ - tmin_) / tnums
        self.aa = tmin_ - self.step
        self.xstep = (max_ - min_) / nums
        r"""

        print(un)
        print(lf,toLeg(formula),sep="\n\n",end="\n\n")
        """
        solves = []
        for iVal in range(tnums + 1):

            self.aa = self.aa + self.step
            self.aa = float("%.10f" % self.aa)
            xValue = min_ - self.xstep
            for XVAL in range(nums + 1):
                lf, un = legalSet(toLeg(formula))
                xValue += self.xstep
                xValue = float("%.10f" % xValue)

                def key(item):
                    if "t" in item[0] or "y" in item[0]:
                        return 1
                    else:
                        return 999

                bf = dict(enumerate(lf))
                lf = sorted(lf, key=key)
                nun = []
                for i in range(len(lf)):
                    nun.insert(lf.index(bf[i]), un[i])
                un = nun
                del nun
                idx = -1
                for imp in un:
                    idx += 1
                    for __imp in imp:
                        if __imp == 't':
                            un[idx].remove("t")
                        if __imp == 'y':
                            un[idx].remove("x")
                del idx

                repl = {"t": [str(self.aa)], "y": [str(xValue)]}
                is_exit = False
                times = -1
                while not is_exit:
                    times += 1

                    if times >= 20:
                        print(f"\nmessage:目前已经循环求解超过20次,目前初始代入值为:y{repl['y']},t{repl['t']},\n"
                              f"已经求解{repl},剩{4 - len(repl.values())}值不可求解,故不予求解并跳出循环")
                        break
                    indx = -1
                    for lf_ in lf:
                        indx += 1
                        for i in repl.keys():
                            for j in range(2):
                                lf_[j] = lf_[j].replace(" " + i, str(repl[i][0]))

                        idx = -1
                        for imp in un:
                            idx += 1
                            for __imp in imp:
                                if __imp in repl.keys():
                                    un[idx].remove(__imp)
                        del idx

                        if un[indx] == []:
                            del un[indx]
                            del lf[indx]
                            if indx == 0 or (indx - 1) >= len(lf): break
                            indx -= 1
                            continue

                        try:
                            ams = sympy.solve(tuple(lf_), tuple(un[indx]))
                            if ams == []:
                                newlf = []
                                for i in lf_:
                                    newlf.append(i.replace(str(repl["y"]), str(repl["y"]) + "*sympy.I"))
                                ams = sympy.solve(tuple(newlf), tuple(un[indx]))
                        except NotImplementedError as err:
                            print(err)
                            no_ans()
                            return

                        if isinstance(ams, (dict,)):
                            for km, jj in ams.items():
                                if not ('x' in str(jj) or
                                        'y' in str(jj) or
                                        'z' in str(jj) or
                                        't' in str(jj)):
                                    if km.name in repl.keys():
                                        repl[km.name].append(str(jj))
                                    else:
                                        repl[km.name] = [str(jj)]
                        else:
                            ix = -1
                            undo = 0
                            for i in ams:
                                ix += 1
                                try:
                                    if isinstance(i, (sympy.core.numbers.Float,
                                                      sympy.core.numbers.Integer,
                                                      int, float, complex)):

                                        try:
                                            repl[tuple(un[indx])[ix]] = [str(eval(str(i)))]
                                        except IndexError:

                                            repl[tuple(un[indx])[undo]].append(str(eval(str(i))))
                                        for i in repl.keys():
                                            if i in lf_:
                                                lf_ = lf_.replace(i, str(repl[i][0]))
                                    elif isinstance(i, (tuple, list, set)):
                                        inxx = -1
                                        for jj in i:
                                            inxx += 1
                                            if not ('x' in str(jj) or
                                                    'y' in str(jj) or
                                                    'z' in str(jj) or
                                                    't' in str(jj)):
                                                try:
                                                    repl[tuple(un[indx][inxx])[ix]] = [str(jj)]
                                                except IndexError:
                                                    repl[tuple(un[indx][inxx])[undo]].append(str(jj))
                                    else:
                                        continue
                                except TypeError as err:
                                    print("get:err", err)
                                    continue
                                else:
                                    undo = ix
                        if len(repl.values()) >= 4: is_exit = True;break
                if is_exit:
                    solves.append(repl)
                if printout:
                    print(f"\r{(iVal * (nums + 1) + XVAL + 1) / ((nums + 1) * (tnums + 1)) * 100}%", end="",
                          flush=True)

        if printout:
            print("\nsucceed in Calculating Values...")
        num = 0
        for i in solves:
            if printout:
                print(f"\r{(num + 1) / len(solves) * 100}%", end="", flush=True)
            num += 1
            x_ = []
            for j in i["x"]:
                x_.append(eval(j))
            x.append(x_)
            y_ = []
            for j in i["y"]:
                y_.append(eval(j))
            y.append(y_)
            z_ = []
            for j in i["z"]:
                z_.append(eval(j))
            z.append(z_)
            t_ = []
            for j in i["t"]:
                t_.append(eval(j))
            t.append(t_)

        del x_, y_, z_, t_, solves

        if printout:
            print("\nsucceed in Saving Values...")

    def _write_t_z(self, formula, tmin_=-10, tmax_=10, tnums=100,
                   min_=-10, max_=10, nums=100, printout=True):

        global x, y, z, t

        self.step = (tmax_ - tmin_) / tnums
        self.aa = tmin_ - self.step
        self.xstep = (max_ - min_) / nums
        r"""

        print(un)
        print(lf,toLeg(formula),sep="\n\n",end="\n\n")
        """
        solves = []
        for iVal in range(tnums + 1):

            self.aa = self.aa + self.step
            self.aa = float("%.10f" % self.aa)
            xValue = min_ - self.xstep
            for XVAL in range(nums + 1):
                lf, un = legalSet(toLeg(formula))
                xValue += self.xstep
                xValue = float("%.10f" % xValue)

                def key(item):
                    if "t" in item[0] or "z" in item[0]:
                        return 1
                    else:
                        return 999

                bf = dict(enumerate(lf))
                lf = sorted(lf, key=key)
                nun = []
                for i in range(len(lf)):
                    nun.insert(lf.index(bf[i]), un[i])
                un = nun
                del nun
                idx = -1
                for imp in un:
                    idx += 1
                    for __imp in imp:
                        if __imp == 't':
                            un[idx].remove("t")
                        if __imp == 'z':
                            un[idx].remove("z")
                del idx

                repl = {"t": [str(self.aa)], "z": [str(xValue)]}
                is_exit = False
                times = -1
                while not is_exit:
                    times += 1

                    if times >= 20:
                        print(f"\nmessage:目前已经循环求解超过20次,目前初始代入值为:z{repl['z']},t{repl['t']},\n"
                              f"已经求解{repl},剩{4 - len(repl.values())}值不可求解,故不予求解并跳出循环")
                        break
                    indx = -1
                    for lf_ in lf:
                        indx += 1
                        for i in repl.keys():
                            for j in range(2):
                                lf_[j] = lf_[j].replace(" " + i, str(repl[i][0]))

                        idx = -1
                        for imp in un:
                            idx += 1
                            for __imp in imp:
                                if __imp in repl.keys():
                                    un[idx].remove(__imp)
                        del idx

                        if un[indx] == []:
                            del un[indx]
                            del lf[indx]
                            if indx == 0 or (indx - 1) >= len(lf): break
                            indx -= 1
                            continue

                        try:
                            ams = sympy.solve(tuple(lf_), tuple(un[indx]))
                            if ams == []:
                                newlf = []
                                for i in lf_:
                                    newlf.append(i.replace(str(repl["z"]), str(repl["z"]) + "*sympy.I"))
                                ams = sympy.solve(tuple(newlf), tuple(un[indx]))
                        except NotImplementedError as err:
                            print(err)
                            no_ans()
                            return

                        if isinstance(ams, (dict,)):
                            for km, jj in ams.items():
                                if not ('x' in str(jj) or
                                        'y' in str(jj) or
                                        'z' in str(jj) or
                                        't' in str(jj)):
                                    if km.name in repl.keys():
                                        repl[km.name].append(str(jj))
                                    else:
                                        repl[km.name] = [str(jj)]
                        else:
                            ix = -1
                            undo = 0
                            for i in ams:
                                ix += 1
                                try:
                                    if isinstance(i, (sympy.core.numbers.Float,
                                                      sympy.core.numbers.Integer,
                                                      int, float, complex)):

                                        try:
                                            repl[tuple(un[indx])[ix]] = [str(eval(str(i)))]
                                        except IndexError:

                                            repl[tuple(un[indx])[undo]].append(str(eval(str(i))))
                                        for i in repl.keys():
                                            if i in lf_:
                                                lf_ = lf_.replace(i, str(repl[i][0]))
                                    elif isinstance(i, (tuple, list, set)):
                                        inxx = -1
                                        for jj in i:
                                            inxx += 1
                                            if not ('x' in str(jj) or
                                                    'y' in str(jj) or
                                                    'z' in str(jj) or
                                                    't' in str(jj)):
                                                try:
                                                    repl[tuple(un[indx][inxx])[ix]] = [str(jj)]
                                                except IndexError:
                                                    repl[tuple(un[indx][inxx])[undo]].append(str(jj))
                                    else:
                                        continue
                                except TypeError as err:
                                    print("get:err", err)
                                    continue
                                else:
                                    undo = ix
                        if len(repl.values()) >= 4: is_exit = True;break
                if is_exit:
                    solves.append(repl)
                if printout:
                    print(f"\r{(iVal * (nums + 1) + XVAL + 1) / ((nums + 1) * (tnums + 1)) * 100}%", end="",
                          flush=True)

        if printout:
            print("\nsucceed in Calculating Values...")
        num = 0
        for i in solves:
            if printout:
                print(f"\r{(num + 1) / len(solves) * 100}%", end="", flush=True)
            num += 1
            x_ = []
            for j in i["x"]:
                x_.append(eval(j))
            x.append(x_)
            y_ = []
            for j in i["y"]:
                y_.append(eval(j))
            y.append(y_)
            z_ = []
            for j in i["z"]:
                z_.append(eval(j))
            z.append(z_)
            t_ = []
            for j in i["t"]:
                t_.append(eval(j))
            t.append(t_)

        del x_, y_, z_, t_, solves

        if printout:
            print("\nsucceed in Saving Values...")

    def _write_t(self, formula, tmin_=-10, tmax_=10, tnums=100, printout=True):

        global x, y, z, t
        I = 1j
        oo = inf

        self.step = (tmax_ - tmin_) / tnums
        self.aa = tmin_ - self.step
        r"""

        print(un)
        print(lf,toLeg(formula),sep="\n\n",end="\n\n")
        """
        solves = []
        for iVal in range(tnums + 1):

            self.aa = self.aa + self.step
            self.aa = float("%.10f" % self.aa)
            lf, un = legalSet(toLeg(formula))

            def key(item):
                if "t" in item[0]:
                    return 1
                else:
                    return 999

            bf = dict(enumerate(lf))
            lf = sorted(lf, key=key)
            nun = []
            for i in range(len(lf)):
                nun.insert(lf.index(bf[i]), un[i])
            un = nun
            del nun
            idx = -1
            for imp in un:
                idx += 1
                for __imp in imp:
                    if __imp == 't':
                        un[idx].remove("t")
            del idx

            repl = {"t": [str(self.aa)]}
            is_exit = False

            times = -1
            while not is_exit:
                times += 1

                if times >= 20:
                    print(f"\nmessage:目前已经循环求解超过20次,目前初始代入值为:t{repl['t']},\n"
                          f"已经求解{repl},剩{4 - len(repl.values())}值不可求解,故不予求解并跳出循环")
                    break
                indx = -1
                for lf_ in lf:
                    indx += 1
                    for i in repl.keys():
                        for j in range(2):
                            if str(i) in str(lf_[j]):
                                lf_[j] = lf_[j].replace(i, str(repl[i][0]))

                    idx = -1
                    for imp in un:
                        idx += 1
                        for __imp in imp:
                            if __imp in repl.keys():
                                un[idx].remove(__imp)
                    del idx

                    if un[indx] == []:
                        del un[indx]
                        del lf[indx]
                        if indx == 0 or (indx - 1) >= len(lf): break
                        indx -= 1
                        continue

                    try:
                        ams = sympy.solve(tuple(lf_), tuple(un[indx]))
                    except NotImplementedError as err:
                        print(err)
                        no_ans()
                        return

                    if isinstance(ams, (dict,)):
                        for km, jj in ams.items():
                            if not ('x' in str(jj) or
                                    'y' in str(jj) or
                                    'z' in str(jj) or
                                    't' in str(jj)):
                                if km.name in repl.keys():
                                    repl[km.name].append(str(jj))
                                else:
                                    repl[km.name] = [str(jj)]
                    else:
                        ix = -1
                        undo = 0
                        for i in ams:
                            ix += 1
                            try:
                                if isinstance(i, (sympy.core.numbers.Float,
                                                  sympy.core.numbers.Integer,
                                                  int, float, complex)):

                                    try:
                                        repl[tuple(un[indx])[ix]] = [str(eval(str(i)))]
                                    except IndexError:

                                        repl[tuple(un[indx])[undo]].append(str(eval(str(i))))
                                    for i in repl.keys():
                                        if i in lf_:
                                            lf_ = lf_.replace(i, str(repl[i][0]))
                                elif isinstance(i, (tuple, list, set)):
                                    inxx = -1
                                    for jj in i:
                                        inxx += 1
                                        if not ('x' in str(jj) or
                                                'y' in str(jj) or
                                                'z' in str(jj) or
                                                't' in str(jj)):
                                            try:
                                                repl[tuple(un[indx][inxx])[ix]] = [str(jj)]
                                            except IndexError:
                                                repl[tuple(un[indx][inxx])[undo]].append(str(jj))
                                else:
                                    continue
                            except TypeError as err:
                                print("get:err", err)
                                continue
                            else:
                                undo = ix
                    if len(repl.values()) >= 4: is_exit = True;break
            if is_exit:
                solves.append(repl)
            if printout:
                print(f"\r{(iVal + 1) / (tnums + 1) * 100}%", end="",
                      flush=True)

        if printout:
            print("\nsucceed in Calculating Values...")
        num = 0
        for i in solves:
            if printout:
                print(f"\r{(num + 1) / len(solves) * 100}%", end="", flush=True)
            num += 1
            x_ = []
            for j in i["x"]:
                x_.append(eval(j))
            x.append(x_)
            y_ = []
            for j in i["y"]:
                y_.append(eval(j))
            y.append(y_)
            z_ = []
            for j in i["z"]:
                z_.append(eval(j))
            z.append(z_)
            t_ = []
            for j in i["t"]:
                t_.append(eval(j))
            t.append(t_)

        del x_, y_, z_, t_, solves

        if printout:
            print("\nsucceed in Saving Values...")

def format():
    global x,y,z,t
    nx={}
    ny={}
    nz={}
    nt=[]

    vx=[]
    vy=[]
    vz=[]

    for i,j,k,v in zip(x,y,z,t):
        for it,jt,kt,vt in zip(i,j,k,v):

            if vt not in nx.keys():
                nx[vt]=[]
            if vt not in ny.keys():
                ny[vt]=[]
            if vt not in nz.keys():
                nz[vt]=[]

            nx[vt].append(it)
            ny[vt].append(jt)
            nz[vt].append(kt)
            nt.append(vt)

    nt.sort()

    for num in set(nt):
        for i,j,k in zip(nx[num],ny[num],nz[num]):
            vx.append(i)
            vy.append(j)
            vz.append(k)

    x=vx
    y=vy
    z=vz
    t=nt



def create_img(tnum, fig=None, ax=None):
    global x, y, z, t

    if fig is None:
        fig = plt.figure()
    if ax is None:
        ax = Axes3D(fig)
        ax.legend(loc='best')
        ax.axis('off')
    if isinstance(tnum, list):
        tnum = tnum[0]
    ax.cla()

    x1 = []
    y1 = []
    z1 = []
    try:
        i = t.index(tnum)
    except (IndexError, ValueError) as err:
        i = 0
    try:
        while t[i] == tnum:
            if isinstance(x[i], (tuple, list, set)):
                x[i] = x[i][0]
            if isinstance(x[i], complex):
                i += 1
                continue
            if isinstance(y[i], (tuple, list, set)):
                y[i] = y[i][0]
            if isinstance(y[i], complex):
                i += 1
                continue
            if isinstance(z[i], (tuple, list, set)):
                z[i] = z[i][0]
            if isinstance(z[i], complex):
                i += 1
                continue
            x1.append(x[i])
            y1.append(y[i])
            z1.append(z[i])
            i += 1
    except IndexError:
        pass

    scatter = ax.scatter(x1, y1, z1, c='r')
    return scatter,

    # plt.savefig('./1.jpg',)


def Graphic_main(formula, modefunc, tmin_=-10, tmax_=10, tnums=100,
                 min_=-10, max_=10, nums=100, printout=True):
    global x, y, z, t
    try:
        modefunc(formula=formula, tmin_=tmin_, tmax_=tmax_, tnums=tnums,
                 min_=min_, max_=max_, nums=nums, printout=printout)
    except Exception:
        modefunc(formula=formula, tmin_=tmin_, tmax_=tmax_, tnums=tnums, printout=printout)
    format()
    fig = plt.figure()



    ax = Axes3D(fig, auto_add_to_figure=False)

    print(min(x),min(y),min(z),"\n",max(x),max(y),max(z))

    ax.set_ylim(min(y),max(y))
    ax.set_xlim(xmin=min(x), xmax=max(x))
    ax.set_zlim(zmin=min(z), zmax=max(z))

    fig.add_axes(ax)


    # ax.legend(loc="best")


    def demo(num):
        a = tmin_ + ((tmax_ - tmin_) / tnums) * (num % tnums)
        print(f"\rwait:{num-tnums}/{tnums}",end="")

        return create_img(a, fig, ax),

    ani = animation.FuncAnimation(fig, demo, fargs=[],
                                  interval=int(((tmax_ - tmin_) / tnums) * 1000))
    ani.save('test.mp4')
    # 调试部分


print("program running")

"""write()._write_t_x("z=t\n3x+y=z\nx=sin(y)",tnums=100,
      printout=True)
print(t)
create_img([0.0])"""
Graphic_main("sin(x)=y\nz=t\ncos(y)=z", modefunc=write()._write_t_x, tnums=10, nums=10)
print("end...")

再次感谢各位的观看!

---------------------------------【完】--------------------------------------

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


学习编程是顺着互联网的发展潮流,是一件好事。新手如何学习编程?其实不难,不过在学习编程之前你得先了解你的目的是什么?这个很重要,因为目的决定你的发展方向、决定你的发展速度。
IT行业是什么工作做什么?IT行业的工作有:产品策划类、页面设计类、前端与移动、开发与测试、营销推广类、数据运营类、运营维护类、游戏相关类等,根据不同的分类下面有细分了不同的岗位。
女生学Java好就业吗?女生适合学Java编程吗?目前有不少女生学习Java开发,但要结合自身的情况,先了解自己适不适合去学习Java,不要盲目的选择不适合自己的Java培训班进行学习。只要肯下功夫钻研,多看、多想、多练
Can’t connect to local MySQL server through socket \'/var/lib/mysql/mysql.sock问题 1.进入mysql路径
oracle基本命令 一、登录操作 1.管理员登录 # 管理员登录 sqlplus / as sysdba 2.普通用户登录
一、背景 因为项目中需要通北京网络,所以需要连vpn,但是服务器有时候会断掉,所以写个shell脚本每五分钟去判断是否连接,于是就有下面的shell脚本。
BETWEEN 操作符选取介于两个值之间的数据范围内的值。这些值可以是数值、文本或者日期。
假如你已经使用过苹果开发者中心上架app,你肯定知道在苹果开发者中心的web界面,无法直接提交ipa文件,而是需要使用第三方工具,将ipa文件上传到构建版本,开...
下面的 SQL 语句指定了两个别名,一个是 name 列的别名,一个是 country 列的别名。**提示:**如果列名称包含空格,要求使用双引号或方括号:
在使用H5混合开发的app打包后,需要将ipa文件上传到appstore进行发布,就需要去苹果开发者中心进行发布。​
+----+--------------+---------------------------+-------+---------+
数组的声明并不是声明一个个单独的变量,比如 number0、number1、...、number99,而是声明一个数组变量,比如 numbers,然后使用 nu...
第一步:到appuploader官网下载辅助工具和iCloud驱动,使用前面创建的AppID登录。
如需删除表中的列,请使用下面的语法(请注意,某些数据库系统不允许这种在数据库表中删除列的方式):
前不久在制作win11pe,制作了一版,1.26GB,太大了,不满意,想再裁剪下,发现这次dism mount正常,commit或discard巨慢,以前都很快...
赛门铁克各个版本概览:https://knowledge.broadcom.com/external/article?legacyId=tech163829
实测Python 3.6.6用pip 21.3.1,再高就报错了,Python 3.10.7用pip 22.3.1是可以的
Broadcom Corporation (博通公司,股票代号AVGO)是全球领先的有线和无线通信半导体公司。其产品实现向家庭、 办公室和移动环境以及在这些环境...
发现个问题,server2016上安装了c4d这些版本,低版本的正常显示窗格,但红色圈出的高版本c4d打开后不显示窗格,
TAT:https://cloud.tencent.com/document/product/1340