Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad superscript positioning for some fonts #5542

Closed
adrn opened this issue Nov 22, 2015 · 5 comments
Closed

Bad superscript positioning for some fonts #5542

adrn opened this issue Nov 22, 2015 · 5 comments
Milestone

Comments

@adrn
Copy link
Contributor

adrn commented Nov 22, 2015

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

v1.4.3, sans serif

1 4 3_sans serif

v1.4.3, CMU serif

1 4 3_cmu serif

v1.5.0, sans serif

1 5 0_sans serif

v1.5.0, CMU serif

1 5 0_cmu serif

Code: https://gist.github.com/adrn/aebd2641be6142dedbdf

@tacaswell
Copy link
Member

This was not intentional and I believe it has been fixed on v1.5.x and master.

attn @zblz @mdboom

@tacaswell tacaswell added this to the Critical bugfix release (1.5.1) milestone Nov 22, 2015
@mdboom
Copy link
Member

mdboom commented 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
Copy link
Member

zblz commented 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
Copy link
Member

mdboom commented 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.

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.

@adrn
Copy link
Contributor Author

adrn commented Nov 23, 2015

Thanks for the ideas @mdboom -- using cmr10 works fine.

@mdboom mdboom modified the milestones: next major release (2.0), Critical bugfix release (1.5.1) Nov 23, 2015
mdboom added a commit to mdboom/matplotlib that referenced this issue Nov 23, 2015
mdboom added a commit to mdboom/matplotlib that referenced this issue Nov 23, 2015
mdboom added a commit to mdboom/matplotlib that referenced this issue Nov 25, 2015
mdboom added a commit to mdboom/matplotlib that referenced this issue Nov 27, 2015
mdboom added a commit to mdboom/matplotlib that referenced this issue Nov 27, 2015
@mdboom mdboom closed this as completed in 48e5cd9 Dec 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants