8000 align titles works · matplotlib/matplotlib@f5de111 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f5de111

Browse files
committed
align titles works
1 parent 8f71fd1 commit f5de111

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,15 +2952,6 @@ def _update_title_position(self, renderer):
29522952

29532953
titles = []
29542954

2955-
# Get grouped axes for alignment if align_titles was previously called
2956-
# grouped_axs = self.figure._align_title_groups.get_siblings(self)
2957-
# if(grouped_axs is not None):
2958-
# titles = []
2959-
# for ax in grouped_axs:
2960-
# titles.extend([ax.title, ax._left_title, ax._right_title])
2961-
# else:
2962-
# titles = [self.title, self._left_title, self._right_title]
2963-
29642955
titles = [self.title, self._left_title, self._right_title]
29652956

29662957
for title in titles:
@@ -3014,12 +3005,24 @@ def _update_title_position(self, renderer):
30143005
title.set_position((x, y))
30153006

30163007
ymax = max(title.get_position()[1] for title in titles)
3017-
# TODO: and for titles in sibling axes according to grouper
30183008
for title in titles:
30193009
# now line up all the titles at the highest baseline.
30203010
x, _ = title.get_position()
30213011
title.set_position((x, ymax))
30223012

3013+
# Assign
3014+
grouped_axs = self.figure._align_title_groups.get_siblings(self)
3015+
ymax = None
3016+
ax_max = None
3017+
for ax in grouped_axs:
3018+
if ymax is None or ax.bbox.ymax > ymax:
3019+
ymax = ax.bbox.ymax
3020+
ax_max = ax
3021+
# print("SELF FIRST: ", self.bbox.xmax)
3022+
# print("OTHER: ", ax_max.bbox.xmax)
3023+
self.bbox = ax_max.bbox
3024+
# print("SELF AFTER: ", self.bbox.xmax)
3025+
30233026
# Drawing
30243027
@martist.allow_rasterization
30253028
def draw(self, renderer):

lib/matplotlib/figure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def __init__(self, **kwargs):
174174
# see self.align_xlabels and self.align_ylabels and
175175
# axis._get_tick_boxes_siblings
176176
self._align_label_groups = {"x": cbook.Grouper(), "y": cbook.Grouper()}
177-
self._align_title_groups = {"title": cbook.Grouper()}
177+
self._align_title_groups = cbook.Grouper()
178178

179179
self.figure = self
180180
# list of child gridspecs for this figure
@@ -1294,7 +1294,7 @@ def align_titles(self, axs=None):
12941294
rowspanc = axc.get_subplotspec().rowspan
12951295
if rowspan.start == rowspanc.start or \
12961296
rowspan.stop == rowspanc.stop:
1297-
self._align_title_groups['title'].join(ax, axc)
1297+
self._align_title_groups.join(ax, axc)
12981298

12991299
def align_ylabels(self, axs=None):
13001300
"""

0 commit comments

Comments
 (0)
0