I like to use Computer Modern as my default font. I noticed that, after updating to v1.5.0, the superscript positioning for tick labels in, e.g., log-log plots is off from what it was in 1.4.3. I've only noticed this difference for CMU Modern, not the default sans-serif fonts. Was this an intentional change? See plots below -- titles specify mpl version number (I moved my matplotlibrc file to make these plots).
The positioning of the sub/superscripts is based on the font in use, and we have hardcoded the values for the fonts that ship with matplotlib, but it's isn't possible to determine them for every font (or even every variation of Computer Modern). Unfortunately, CMU Modern and Computer Modern are not precisely the same font (same source material, different names and character mappings), so when you use CMU Modern matplotlib doesn't know how to position the sub/superscripts correctly. The change between 1.4.3 and 1.5.0 is incidental: whereas before we used the positioning for Computer Modern for everything and you got lucky and every other font had the wrong position, now the positioning is appropriate for DejaVu by default and you're getting unlucky.
@mdboom: DejaVu will only be introduced for 2.0 as default, I believe this comes from the change we made to CM subsuper position in #4873, which went into 1.5.0. It seems that the improved positioning for Bakoma CM makes it worse for CMU.
I have looked at it a bit deeper and it seems that the default formatter for log-scales (LogFormatterMathtext) uses a \mathdefault call around the 10^{-2} strings. This might have been a good idea as long the subsuper position matched both the mathtext and regular fonts (i.e., bakoma and bitstream vera, respectively), but since we tailored the subsuper position to each mathtext fontset, using these positionings for regular text might be ugly (as here).
I think that Bakoma CM and CMU differ here in the height of their superscripted numbers, which CMU rendering them quite larger. Note how the $10^5$ in the x-axis label, which is rendered in Bakoma CM because it is mathtext with mathtext font, looks better than the y-axis tick labels.
An option we have to fix this is to force mathtext font in log-scale labels (i.e., remove mathdefault call). This will result in CM labels in plots with sans elsewhere in 1.5.1, but will not be a problem in 2.0 because the default will be DejaVu for both.
@mdboom: DejaVu will only be introduced for 2.0 as default, I believe this comes from the change we made to CM subsuper position in #4873, which went into 1.5.0. It seems that the improved positioning for Bakoma CM makes it worse for CMU.
Ah, yes. Of course, you're right about that.
An option we have to fix this is to force mathtext font in log-scale labels (i.e., remove mathdefault call). This will result in CM labels in plots with sans elsewhere in 1.5.1, but will not be a problem in 2.0 because the default will be DejaVu for both.
I think we can definitely take the \mathdefault out for 2.0, and that's a good long-term solution in the context of all the other changes in 2.0. For 1.5.1, I don't think so -- I think changing all the log scaling text to Computer Modern is too breaking of a change.
The workaround for @adrn on 1.5 might be to either use text.usetext: True (if you have a working LaTeX install), or use the cmr10 font (the Computer Modern matplotlib ships) and set axes.unicode_minus to False.
Activity
tacaswell commented on Nov 22, 2015
This was not intentional and I believe it has been fixed on v1.5.x and master.
attn @zblz @mdboom
mdboom commented on Nov 23, 2015
The positioning of the sub/superscripts is based on the font in use, and we have hardcoded the values for the fonts that ship with matplotlib, but it's isn't possible to determine them for every font (or even every variation of Computer Modern). Unfortunately, CMU Modern and Computer Modern are not precisely the same font (same source material, different names and character mappings), so when you use CMU Modern matplotlib doesn't know how to position the sub/superscripts correctly. The change between 1.4.3 and 1.5.0 is incidental: whereas before we used the positioning for Computer Modern for everything and you got lucky and every other font had the wrong position, now the positioning is appropriate for DejaVu by default and you're getting unlucky.
I'll have to think on how best to fix this.
zblz commented on Nov 23, 2015
@mdboom: DejaVu will only be introduced for 2.0 as default, I believe this comes from the change we made to CM subsuper position in #4873, which went into 1.5.0. It seems that the improved positioning for Bakoma CM makes it worse for CMU.
I have looked at it a bit deeper and it seems that the default formatter for log-scales (LogFormatterMathtext) uses a \mathdefault call around the 10^{-2} strings. This might have been a good idea as long the subsuper position matched both the mathtext and regular fonts (i.e., bakoma and bitstream vera, respectively), but since we tailored the subsuper position to each mathtext fontset, using these positionings for regular text might be ugly (as here).
I think that Bakoma CM and CMU differ here in the height of their superscripted numbers, which CMU rendering them quite larger. Note how the $10^5$ in the x-axis label, which is rendered in Bakoma CM because it is mathtext with mathtext font, looks better than the y-axis tick labels.
An option we have to fix this is to force mathtext font in log-scale labels (i.e., remove mathdefault call). This will result in CM labels in plots with sans elsewhere in 1.5.1, but will not be a problem in 2.0 because the default will be DejaVu for both.
mdboom commented on Nov 23, 2015
Ah, yes. Of course, you're right about that.
I think we can definitely take the \mathdefault out for 2.0, and that's a good long-term solution in the context of all the other changes in 2.0. For 1.5.1, I don't think so -- I think changing all the log scaling text to Computer Modern is too breaking of a change.
The workaround for @adrn on 1.5 might be to either use text.usetext: True (if you have a working LaTeX install), or use the cmr10 font (the Computer Modern matplotlib ships) and set axes.unicode_minus to False.
adrn commented on Nov 23, 2015
Thanks for the ideas @mdboom -- using cmr10 works fine.
Fix matplotlib#5542: Don't use mathdefault anymore
Fix matplotlib#5542: Don't use mathdefault anymore
Fix matplotlib#5542: Don't use mathdefault anymore
Fix matplotlib#5542: Don't use mathdefault anymore
Fix matplotlib#5542: Don't use mathdefault anymore
Fix matplotlib#5542: Don't use mathdefault anymore