Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python mathtext到wxbitmap函数中特殊情况的实现_Python_Matplotlib_Bitmap_Wxpython_Latex - Fatal编程技术网

Python mathtext到wxbitmap函数中特殊情况的实现

Python mathtext到wxbitmap函数中特殊情况的实现,python,matplotlib,bitmap,wxpython,latex,Python,Matplotlib,Bitmap,Wxpython,Latex,我正在显示这样的位图 使用代码: mt =r'$\frac{%.5fx^{2} + %.5fx + %.5f}{%.5fx^{2} + %.5fx + %.5f}$'%(self.z1[-3],self.z1[-2],self.z1[-1],self.z3[-3],self.z3[-2],self.z3[-1]) bm = mathtext_to_wxbitmap(mt) self.picture.SetBitmap(bm) 在这里,函数mathtext\u to_wxbitmap实现为

我正在显示这样的位图

使用代码:

mt =r'$\frac{%.5fx^{2} + %.5fx + %.5f}{%.5fx^{2} + %.5fx + %.5f}$'%(self.z1[-3],self.z1[-2],self.z1[-1],self.z3[-3],self.z3[-2],self.z3[-1])
bm = mathtext_to_wxbitmap(mt)
self.picture.SetBitmap(bm)  
在这里,函数
mathtext\u to_wxbitmap
实现为:

from matplotlib.mathtext import MathTextParser
mathtext_parser = MathTextParser("Bitmap")
def mathtext_to_wxbitmap(s):
    ftimage, depth = mathtext_parser.parse(s, 150)
    return wx.BitmapFromBufferRGBA(
        ftimage.get_width(), ftimage.get_height(),
        ftimage.as_rgba_str())
第一个代码段中的
z1
z3
是值不断变化的列表,相应地位图也不断更新这一切都很好。

问题出现在以下情况中:

案例1:

当其中一个系数为0时

如果系数为0,我希望术语
0.00000x
2
不应显示

案例2:

当系数为负时

如果系数为负,我只想要
-2.12321
,而不是
+-2.12321

案例3:

当所有系数都是整数时

我明白了-

但我希望它是这样的-


如能帮助解决上述任何一种情况,我们将不胜感激。我愿意以完全不同的方式实现这一点,如果有的话

是的,我还注意到
0*x**2
看起来不太好看。我认为您想在这里做的事情超出了matplotlib这样的库的范围

你需要一些“理解”数学公式的东西,比如Mathematica或Mathcad或…。您最终将编写自己的输出格式化程序

在python中,我想到的唯一现成的东西是sympy库。它可以将公式渲染为文本,还可以对公式进行简化。如果您想试一试,它还有一个渲染器,为支持unicode的终端输出unicode公式

如果您可以使用相同的unicode字体(未测试!),我假设它的输出可以在wxPython文本框中以1:1的比例显示