You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the improvements to matplotlib 1.3.0 is supposed to be improved vertical alignment of text, but it appears to have gotten worse in my experience. Here is an example:
The numbers in the the v1.3.0 png are too high. The numbers should be in the center of the rectangular boxes, and the center of the tick mark numbers should line up with the tick marks.
I am wondering if this is related to changes in how the text's baseline is
treated. Also, wasn't there differences with how Agg handled it and PDF and
other backends handled it?
My guess is that texts seem to high because of the extra padding below the texts. One of the change made by @mdboom is that a minimum descent (the descent of "g") is accounted when the bounding box is calculated. The advantage of this is that the bounding boxes of different texts look consistent (e.g., bounding boxes of "a" and "g" look similar). But some may feel that there are too much space. I am not sure if there is an option to change the default behavior.
Yeah, in my humble opinion, "g" should have a different bounding box than "a", but they should have the same baseline. Perhaps there is a reason to make all characters have the same bounding box, but, in my view, the bounding box reflects that different characters are different dimensions. When I want to treat different characters as if they were the same size, then I just use some multiple of the font size.
For example, I can center the text inside the squares (see my original post) by aligning the squares to the text bounding box. Tick mark labels, on the other hand, can be vertically aligned according to the baseline and half the font size.
Well, if you put in the option to switch how the bounding box is calculated, either behavior as a default is fine with me. The real lure of matplotlib for me is it's customizability.
@mdboom made a reference to this issue on issue 2519. He said, "In 1.3.0, the bounding box now includes the descenders. This is a bugfix for a number of layout problems in the legend and elsewhere, and I consider the new behavior correct." This echoes the comment above by @leejjoon .
I am kind of surprised to hear that this is considered correct behavior. Take a look at the tick mark labels for the vertical axis in the v1.2.1 plot above. The vertical center of the numbers are nicely aligned with the tick marks. In the v1.3.0 plot above, the numbers are all too high relative to their respective tick marks.
Perhaps there is some kind of middle ground that continues to fix the layout problems that @mdboom refers to, while also fixing the issues I've pointed out.
@mdboom, is there some possible compromise? Maybe reduce the bottom padding? Aesthetically, @breedlun is right; for numbers or anything without descenders, the present centering doesn't look good.
I finally got around to trying v2.0. The alignment of vertical tick mark labels looks great! In addition, I noticed that the subscripts and superscripts generated by mathtext have better vertical positioning too. Thanks @mdboom! Virtually none of the default changes in v2.0 affect me (I have all my own defaults set up), but the improved vertical alignment/positioning made the upgrade worth it.
Activity
pelson commentedon Oct 18, 2013
Pinging @leejjoon just in case you have any ideas.
WeatherGod commentedon Oct 18, 2013
I am wondering if this is related to changes in how the text's baseline is
treated. Also, wasn't there differences with how Agg handled it and PDF and
other backends handled it?
leejjoon commentedon Oct 20, 2013
My guess is that texts seem to high because of the extra padding below the texts. One of the change made by @mdboom is that a minimum descent (the descent of "g") is accounted when the bounding box is calculated. The advantage of this is that the bounding boxes of different texts look consistent (e.g., bounding boxes of "a" and "g" look similar). But some may feel that there are too much space. I am not sure if there is an option to change the default behavior.
breedlun commentedon Oct 20, 2013
Yeah, in my humble opinion, "g" should have a different bounding box than "a", but they should have the same baseline. Perhaps there is a reason to make all characters have the same bounding box, but, in my view, the bounding box reflects that different characters are different dimensions. When I want to treat different characters as if they were the same size, then I just use some multiple of the font size.
For example, I can center the text inside the squares (see my original post) by aligning the squares to the text bounding box. Tick mark labels, on the other hand, can be vertically aligned according to the baseline and half the font size.
Well, if you put in the option to switch how the bounding box is calculated, either behavior as a default is fine with me. The real lure of matplotlib for me is it's customizability.
breedlun commentedon Jan 16, 2014
@mdboom made a reference to this issue on issue 2519. He said, "In 1.3.0, the bounding box now includes the descenders. This is a bugfix for a number of layout problems in the legend and elsewhere, and I consider the new behavior correct." This echoes the comment above by @leejjoon .
I am kind of surprised to hear that this is considered correct behavior. Take a look at the tick mark labels for the vertical axis in the v1.2.1 plot above. The vertical center of the numbers are nicely aligned with the tick marks. In the v1.3.0 plot above, the numbers are all too high relative to their respective tick marks.
Perhaps there is some kind of middle ground that continues to fix the layout problems that @mdboom refers to, while also fixing the issues I've pointed out.
tacaswell commentedon Feb 21, 2014
@mdboom Can you take another look it this?
efiring commentedon Feb 15, 2016
@mdboom, is there some possible compromise? Maybe reduce the bottom padding? Aesthetically, @breedlun is right; for numbers or anything without descenders, the present centering doesn't look good.
Fix matplotlib#2527: Align y-ticks without descenders
Fix matplotlib#2527: Align y-ticks without descenders
breedlun commentedon Apr 15, 2016
Does #6200 fix the vertical alignment for all text, or just y-tick mark text?
tacaswell commentedon Apr 15, 2016
Just y tick by default, but introduced a new alignment value you can use
anywhere.
On Thu, Apr 14, 2016, 20:45 Benjamin Reedlunn [email protected]
wrote:
breedlun commentedon Apr 15, 2016
OK. I will try out this new alignment value before v2.0 gets released.
breedlun commentedon Feb 5, 2017
I finally got around to trying v2.0. The alignment of vertical tick mark labels looks great! In addition, I noticed that the subscripts and superscripts generated by mathtext have better vertical positioning too. Thanks @mdboom! Virtually none of the default changes in v2.0 affect me (I have all my own defaults set up), but the improved vertical alignment/positioning made the upgrade worth it.