在mathtext到wxbitmap功能的特殊情况下Implementaion [英] Implementaion of particular cases in a mathtext to wxbitmap function

查看:208
本文介绍了在mathtext到wxbitmap功能的特殊情况下Implementaion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显示一个像这样的位图

I am displaying a bitmap like this

使用code:

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_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 第一code段是列表,其价值不断变化和相应的位图不断更新。 这一切工作正常。

The z1 and z3 in the first code snippet are lists whose value keep changing and accordingly the bitmap keeps updating. This all works fine.

的问题是在下列情况下:

The problem is in the following cases :

案例1:

当系数之一,是0。

我想这个词 0.00000x 2 不应该被显示在所有如果系数是0

I want that the term 0.00000x2 should not be displayed at all if the coefficient is 0.

案例2:

当系数为负。

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

Instead of +-2.12321 I want only -2.12321 if the coefficient is negative.

案例3:

当所有的系数都是整数

我得到这个 -

但我希望它像 -

在解决的任何的上述情况的任何帮助AP preciated。我愿意在一个完全不同的方式实现这一点,如果有一个。

Any help in solving any of the above cases is appreciated. I am open to implementing this in a completely different way if there is one.

推荐答案

是的,我还注意到, 0 * X ** 2 看起来并不很漂亮。我想你想在这里做的是出像matplotlib库的范围。

Yes, I also was noting that 0 * x**2 does not look very nice. I think what you want to do here is out of the scope of libraries like matplotlib.

您需要的一些东西,理解数学公式,数学一样的Mathcad或者...或者。你最终会写自己的输出格式。

You need something which "understands" mathematic formulas, like Mathematica or Mathcad or …. You would end up writing your own output formatter.

这在我脑海中的python的唯一现成的东西是sympy库。它可以使公式为文本,也将做公式简化。如果你想给它一个镜头,它也有一个 prettyPrinter 渲染输出UNI code公式UNI code感知终端。

The only ready-made thing which comes to my mind in python is the sympy library. It can render formulas to text and will also do simplification on formulas. If you want to give it a shot, it also has a PrettyPrinter renderer outputting unicode formulas for unicode-aware terminals.

我presume其输出可以显示1:(!未经测试)。在wxPython的文本框中1,如果你可以使用相同的UNI code字型

I presume its output could be displayed 1:1 in a wxPython text box if you can use the same unicode font (untested!).

这篇关于在mathtext到wxbitmap功能的特殊情况下Implementaion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆