python - Implementaion of particular cases in a mathtext to wxbitmap function -


i displaying bitmap

enter image description here

using 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)   

here function mathtext_to_wxbitmap implemented :

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()) 

the z1 , z3 in first code snippet lists value keep changing , accordingly bitmap keeps updating. this works fine.

the problem in following cases :

case 1:

when 1 of coefficient 0.

enter image description here

i want term 0.00000x2 should not displayed @ if coefficient 0.

case 2:

when coefficient negative.

enter image description here

instead of +-2.12321 want -2.12321 if coefficient negative.

case 3:

when coefficients integers

i getting -

enter image description here

but want like-

enter image description here

any in solving any of above cases appreciated. open implementing in different way if there one.

yes, noting 0 * x**2 not nice. think want here out of scope of libraries matplotlib.

you need "understands" mathematic formulas, mathematica or mathcad or …. end writing own output formatter.

the ready-made thing comes mind in python sympy library. can render formulas text , simplification on formulas. if want give shot, has prettyprinter renderer outputting unicode formulas unicode-aware terminals.

i presume output displayed 1:1 in wxpython text box if can use same unicode font (untested!).


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -