From de54b0364e6b6c6ff04ad220f20547228712dd35 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 14 Mar 2020 20:19:59 +0100 Subject: [PATCH] Cleanup demo_axes_hbox_divider. - Small rewording. - Use the make_heights_equal function demo'ed in the example, rather than copy-pasting it. - For the central annotation, use a figure-level text() instead of an invisible axes. --- examples/axes_grid1/demo_axes_hbox_divider.py | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/examples/axes_grid1/demo_axes_hbox_divider.py b/examples/axes_grid1/demo_axes_hbox_divider.py index e244b4dd4e78..7bbbeff950a6 100644 --- a/examples/axes_grid1/demo_axes_hbox_divider.py +++ b/examples/axes_grid1/demo_axes_hbox_divider.py @@ -1,9 +1,9 @@ """ -====================== -Demo Axes Hbox Divider -====================== +=================== +`.HBoxDivider` demo +=================== -Hbox Divider to arrange subplots. +Using an `.HBoxDivider` to arrange subplots. """ import numpy as np @@ -31,22 +31,13 @@ def make_heights_equal(fig, rect, ax1, ax2, pad): ax1.imshow(arr1) ax2.imshow(arr2) - pad = 0.5 # inches. - divider = HBoxDivider( - fig, 111, # Position of combined axes. - horizontal=[Size.AxesX(ax1), Size.Fixed(pad), Size.AxesX(ax2)], - vertical=[Size.AxesY(ax1), Size.Scaled(1), Size.AxesY(ax2)]) - ax1.set_axes_locator(divider.new_locator(0)) - ax2.set_axes_locator(divider.new_locator(2)) + make_heights_equal(fig, 111, ax1, ax2, pad=0.5) - # annotate - ax3 = plt.axes([0.5, 0.5, 0.001, 0.001], frameon=False) - ax3.xaxis.set_visible(False) - ax3.yaxis.set_visible(False) - ax3.annotate("Location of two axes are adjusted\n" - "so that they have equal heights\n" - "while maintaining their aspect ratios", (0.5, 0.5), - xycoords="axes fraction", va="center", ha="center", - bbox=dict(boxstyle="round, pad=1", fc="w")) + fig.text(.5, .5, + "Both axes' location are adjusted\n" + "so that they have equal heights\n" + "while maintaining their aspect ratios", + va="center", ha="center", + bbox=dict(boxstyle="round, pad=1", facecolor="w")) plt.show()