Skip to content

Commit 676964a

Browse files
committed
Stop double-scaling vertical text margins by aspect ratio
margin.to("fig") returns top/bottom values as fractions of figure height already; the layout code was multiplying them by F = W/H a second time, making vertical text margins grow with the aspect ratio. Remove the extra * F on m.t / m.b in the top/bottom side-space calculations in both plot and composition layouts. Regenerate baseline images affected by the corrected spacing.
1 parent 4336c3b commit 676964a

344 files changed

Lines changed: 18 additions & 18 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

plotnine/_mpl/layout_manager/_composition_side_space.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ def _calculate(self):
155155

156156
if items.plot_title:
157157
m = theme.get_margin("plot_title").fig
158-
self.plot_title_margin_top = m.t * F
158+
self.plot_title_margin_top = m.t
159159
self.plot_title = geometry.height(items.plot_title)
160-
self.plot_title_margin_bottom = m.b * F
160+
self.plot_title_margin_bottom = m.b
161161

162162
if items.plot_subtitle:
163163
m = theme.get_margin("plot_subtitle").fig
164-
self.plot_subtitle_margin_top = m.t * F
164+
self.plot_subtitle_margin_top = m.t
165165
self.plot_subtitle = geometry.height(items.plot_subtitle)
166-
self.plot_subtitle_margin_bottom = m.b * F
166+
self.plot_subtitle_margin_bottom = m.b
167167

168168
@property
169169
def offset(self) -> float:
@@ -236,15 +236,15 @@ def _calculate(self):
236236
self.plot_margin = theme.getp("plot_margin_bottom") * F
237237
if items.plot_footer:
238238
m = theme.get_margin("plot_footer").fig
239-
self.plot_footer_margin_bottom = m.b * F
239+
self.plot_footer_margin_bottom = m.b
240240
self.plot_footer = geometry.height(items.plot_footer)
241-
self.plot_footer_margin_top = m.t * F
241+
self.plot_footer_margin_top = m.t
242242

243243
if items.plot_caption:
244244
m = theme.get_margin("plot_caption").fig
245-
self.plot_caption_margin_bottom = m.b * F
245+
self.plot_caption_margin_bottom = m.b
246246
self.plot_caption = geometry.height(items.plot_caption)
247-
self.plot_caption_margin_top = m.t * F
247+
self.plot_caption_margin_top = m.t
248248

249249
@property
250250
def offset(self) -> float:

plotnine/_mpl/layout_manager/_plot_side_space.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -458,15 +458,15 @@ def _calculate(self):
458458

459459
if items.plot_title:
460460
m = theme.get_margin("plot_title").fig
461-
self.plot_title_margin_top = m.t * F
461+
self.plot_title_margin_top = m.t
462462
self.plot_title = geometry.height(items.plot_title)
463-
self.plot_title_margin_bottom = m.b * F
463+
self.plot_title_margin_bottom = m.b
464464

465465
if items.plot_subtitle:
466466
m = theme.get_margin("plot_subtitle").fig
467-
self.plot_subtitle_margin_top = m.t * F
467+
self.plot_subtitle_margin_top = m.t
468468
self.plot_subtitle = geometry.height(items.plot_subtitle)
469-
self.plot_subtitle_margin_bottom = m.b * F
469+
self.plot_subtitle_margin_bottom = m.b
470470

471471
if items.legends and items.legends.top:
472472
self.legend = self.legend_height
@@ -601,25 +601,25 @@ def _calculate(self):
601601

602602
if items.plot_caption:
603603
m = theme.get_margin("plot_caption").fig
604-
self.plot_caption_margin_bottom = m.b * F
604+
self.plot_caption_margin_bottom = m.b
605605
self.plot_caption = geometry.height(items.plot_caption)
606-
self.plot_caption_margin_top = m.t * F
606+
self.plot_caption_margin_top = m.t
607607

608608
if items.plot_footer:
609609
m = theme.get_margin("plot_footer").fig
610-
self.plot_footer_margin_bottom = m.b * F
610+
self.plot_footer_margin_bottom = m.b
611611
self.plot_footer = geometry.height(items.plot_footer)
612-
self.plot_footer_margin_top = m.t * F
612+
self.plot_footer_margin_top = m.t
613613

614614
if items.legends and items.legends.bottom:
615615
self.legend = self.legend_height
616616
self.legend_box_spacing = theme.getp("legend_box_spacing") * F
617617

618618
if items.axis_title_x:
619619
m = theme.get_margin("axis_title_x").fig
620-
self.axis_title_x_margin_bottom = m.b * F
620+
self.axis_title_x_margin_bottom = m.b
621621
self.axis_title_x = geometry.height(items.axis_title_x)
622-
self.axis_title_x_margin_top = m.t * F
622+
self.axis_title_x_margin_top = m.t
623623

624624
# Account for the space consumed by the axis
625625
self.axis_text_x = items.axis_text_x_max_height_at("last_row")
-222 Bytes
-75 Bytes
-537 Bytes
-411 Bytes
-686 Bytes
-655 Bytes
-1.13 KB
6 Bytes

0 commit comments

Comments
 (0)