Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2db893

Browse files
committed
DOC: Whats new entry for title moving above xaxis
1 parent a0f10b9 commit c2db893

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
Axes title will no longer overlap xaxis
22
---------------------------------------
33

4-
Previously the axes title had to be moved manually if an xaxis overlapped
5-
(usually when the xaxis was put on the top of the axes). The title can
6-
still be placed manually. However, titles that need to be moved are
7-
at ``y=1.0``, so manualy placing at 1.0 will be moved, so if the title
8-
is to be placed at 1.0, it should be set to something near 1.0, like 1.001.
4+
Previously an axes title had to be moved manually if an xaxis overlapped
5+
(usually when the xaxis was put on the top of the axes). Now, the title
6+
will be automatically moved above the xaxis and its decorators (including
7+
the xlabel) if they are at the top.
8+
9+
If desired, the title can still be placed manually. There is a slight kludge;
10+
the algorithm checks if the y-position of the title is 1.0 (the default),
11+
and moves if it is. If the user places the title in the default location
12+
(i.e. ``ax.title.set_position(0.5, 1.0)``), the title will still be moved
13+
above the xaxis. If the user wants to avoid this, they can
14+
specify a number that is close (i.e. ``ax.title.set_position(0.5, 1.01)``)
15+
and the title will not be moved via this algorithm.

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2485,7 +2485,7 @@ def _update_title_position(self, renderer):
24852485
if (ax.xaxis.get_label_position() == 'top'
24862486
or ax.xaxis.get_ticks_position() == 'top'):
24872487
bb = ax.xaxis.get_tightbbox(renderer)
2488-
top = bb.y1
2488+
top = bb.ymax
24892489
# we don't need to pad because the padding is already
24902490
# in __init__: titleOffsetTrans
24912491
yn = self.transAxes.inverted().transform((0., top))[1]

0 commit comments

Comments
 (0)