TL; DR In the next line of mathtext.py line 727 an error appears. It associates a valid Bigg bracket with the index '\x21' , but it is the index for the exclamation point. A line with little context reads
_size_alternatives = { '(' : [('rm', '('), ('ex', '\xa1'), ('ex', '\xb3'), ('ex', '\xb5'), ('ex', '\xc3')], ')' : [('rm', ')'), ('ex', '\xa2'), ('ex', '\xb4'), ('ex', '\xb6'), ('ex', '\x21')],
I'm not quite sure which index needs to be changed, but I suggest you change the local copy of mathtext.py as follows:
_size_alternatives = { '(' : [('rm', '('), ('ex', '\xa1'), ('ex', '\xb3'), ('ex', '\xb5'), ('ex', '\x28')], ')' : [('rm', ')'), ('ex', '\xa2'), ('ex', '\xb4'), ('ex', '\xb6'), ('ex', '\x29')]
The brackets it produces are a little rounded as they are the main brackets, but they work. Similarly, you can replace the Bigg sizes with '\xb5' and 'xb6'
Matplotlib github Issue 5210 Reported
I can reproduce this problem with size=6 , using the code as provided (made the constant a bit bigger if it was a width problem). I canโt reproduce the โfixโ by setting size = 7 , but I can, if I go up to size = 8 or higher, suppose that it can be an unpleasant error in the edge and, possibly, depending on the system ...
I have done quite a lot of research / diagnoses (see below), but it seems that there is a mistake - reported on matplotlib github here .
However, casting only an example to matplotlib gives a very good one as shown below. Note. I set my matplotlib to use latex rendering by default - but you can explicitly set the parameters for the same results.
The code
import matplotlib.pyplot as plt import matplotlib as mpl mpl.rc('image', origin='upper') mpl.rc('text', usetex=True) DefaultProps = mpl.font_manager.FontProperties(family = "sans-serif",\ style = "normal",\ weight = "medium",\ size = 6) EXP = r'$\left(\frac{A \cdot \left(vds \cdot rs + \operatorname{Vdp}\left(ri, Rn, Hr, Hd\right) \cdot rh\right) \cdot \left(rSurf + \left(1.0 - rSurf\right) \cdot ft\right) \cdot \left(1.0 - e^{- \left(\left(lr + \frac{\operatorname{Log}\left(2\right)}{tem \cdot 86400.0}\right)\right) \cdot tFr \cdot 3600.0}\right)}{rc \cdot \left(lr + \frac{\operatorname{Log}\left(2\right)}{tem \cdot 86400.0}\right) \cdot tFr \cdot 3600.0} + 10589 \right)$' plt.title(EXP, fontsize=6) plt.gca().set_axis_off()
Exit
The output window is cropped and slightly enlarged for clarity, but you can see the bracket displays OK

This suggests that the problem is either in how matplotlib uses the rendering engine, output to a bitmap, or interact with wxPython
From an experiment, I noticed that if you increase the dpi to 300, the code works fine in size = 6 , but it starts crashing in size = 3 again. This means that the problem is that one of the libraries does not believe that it can display an element in a certain number of pixels.
Root cause
Diagnosing which bit does this is hard (IMO)
First, I added
self.parser.to_png('D:\\math_out.png', _s, color=u'black', dpi=150)
as the first line of mathtext_to_wxbitmap(self, _s, dpi = 150, prop = DefaultProps) . This gave a nice png result, making me think that apparently it was not a matplotlib parser ... EDIT based on @Baptiste's helpful answer , I checked this a bit more. In fact - if I explicitly pass fontsize this call, I can reproduce the look of the exclamation mark. In addition, the dpi passed to this call is ignored - so in my tests, I actually deal with a resolution of 300 dpi. Thus, the focus should be based on MathTextParser , and this may be a problem with dpi resolution.
Further research
A bit more research - I monkey paid to install matplotlib - adding print(result) immediately after calling parseString() here , with a working expression that works great and prints a text view. With a listened script, I see:
Traceback (most recent call last): File "D:\baptiste_test.py", line 9, in <module> parser.to_png(filename, s, fontsize=size) File "C:\Python27\lib\site-packages\matplotlib\mathtext.py", line 3101, in to_ png rgba, depth = self.to_rgba(texstr, color=color, dpi=dpi, fontsize=fontsize) File "C:\Python27\lib\site-packages\matplotlib\mathtext.py", line 3066, in to_ rgba x, depth = self.to_mask(texstr, dpi=dpi, fontsize=fontsize) File "C:\Python27\lib\site-packages\matplotlib\mathtext.py", line 3039, in to_ mask ftimage, depth = self.parse(texstr, dpi=dpi, prop=prop) File "C:\Python27\lib\site-packages\matplotlib\mathtext.py", line 3012, in par se box = self._parser.parse(s, font_output, fontsize, dpi) File "C:\Python27\lib\site-packages\matplotlib\mathtext.py", line 2339, in par se print(result[0]) File "C:\Python27\lib\site-packages\matplotlib\mathtext.py", line 1403, in __r epr__ ' '.join([repr(x) for x in self.children])) File "C:\Python27\lib\site-packages\matplotlib\mathtext.py", line 1403, in __r epr__ ' '.join([repr(x) for x in self.children])) File "C:\Python27\lib\site-packages\matplotlib\mathtext.py", line 1403, in __r epr__ ' '.join([repr(x) for x in self.children])) File "C:\Python27\lib\site-packages\matplotlib\mathtext.py", line 1403, in __r epr__ ' '.join([repr(x) for x in self.children])) UnicodeEncodeError: 'ascii' codec can't encode character u'\xb3' in position 1: ordinal not in range(128)
This indicates that an error may occur in an incorrectly translated character - perhaps missing code in the font?
I also noted that you can play without the letter N in the minimal Baptiste example.
Further research
Holding debugging prints in _get_glyph in the BakomaFonts class. In the unsuccessful case, the code seems to be looking for an exclamation mark (u '!'), When you expect it to look for u '\ xc4' and return parenrightBigg (i.e. where the corresponding left bracket is looking up u '\ xc3 'and returns parenleftBigg). In situations where he uses only parenrightbigg, there is no problem (this happens for fontsize = 5 in this example, but not for others). The debug line that I installed in _get_glyph was:
print('Getting glyph for symbol',repr(unicode(sym))) print('Returning',cached_font, num, symbol_name, fontsize, slanted)
I guess if he needs a bigg or Bigg version based on a combination of fonts and dpi
OK - I think the problem is in this line: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/mathtext.py#L727
this reads (with a little context):
_size_alternatives = { '(' : [('rm', '('), ('ex', '\xa1'), ('ex', '\xb3'), ('ex', '\xb5'), ('ex', '\xc3')], ')' : [('rm', ')'), ('ex', '\xa2'), ('ex', '\xb4'), ('ex', '\xb6'), ('ex', '\x21')], ## <---- Incorrect line.
'\x21' incorrect, but I canโt understand that the correct '\x29' is close, but "too curved." I assumed that '\xc4' follows the pattern, but it is a down arrow. We hope that one of the main developers can easily find this number (195 decimal) against the glyph that it displays and corrects.