diff --git a/examples/axes_grid1/simple_axes_divider1.py b/examples/axes_grid1/simple_axes_divider1.py index 1ca9fd463d81..0b4eb9dd904a 100644 --- a/examples/axes_grid1/simple_axes_divider1.py +++ b/examples/axes_grid1/simple_axes_divider1.py @@ -2,17 +2,25 @@ ===================== Simple Axes Divider 1 ===================== - """ from mpl_toolkits.axes_grid1 import Size, Divider import matplotlib.pyplot as plt +def label_axes(ax, text): + """Place a label at the center of an axes, and remove the axis ticks.""" + ax.text(.5, .5, text, transform=ax.transAxes, + horizontalalignment="center", verticalalignment="center") + ax.tick_params(bottom=False, labelbottom=False, + left=False, labelleft=False) + + ############################################################################## # Fixed axes sizes; fixed paddings. fig = plt.figure(figsize=(6, 6)) +fig.suptitle("Fixed axes sizes, fixed paddings") # Sizes are in inches. horiz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5), Size.Fixed(.5)] @@ -24,17 +32,19 @@ # The rect parameter will actually be ignored and overridden by axes_locator. ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0)) +label_axes(ax1, "nx=0, ny=0") ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2)) +label_axes(ax2, "nx=0, ny=2") ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2)) +label_axes(ax3, "nx=2, ny=2") ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0)) - -for ax in fig.axes: - ax.tick_params(labelbottom=False, labelleft=False) +label_axes(ax4, "nx=2, nx1=4, ny=0") ############################################################################## # Axes sizes that scale with the figure size; fixed paddings. fig = plt.figure(figsize=(6, 6)) +fig.suptitle("Scalable axes sizes, fixed paddings") horiz = [Size.Scaled(1.5), Size.Fixed(.5), Size.Scaled(1.), Size.Scaled(.5)] vert = [Size.Scaled(1.), Size.Fixed(.5), Size.Scaled(1.5)] @@ -45,11 +55,12 @@ # The rect parameter will actually be ignored and overridden by axes_locator. ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0)) +label_axes(ax1, "nx=0, ny=0") ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2)) +label_axes(ax2, "nx=0, ny=2") ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2)) +label_axes(ax3, "nx=2, ny=2") ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0)) - -for ax in fig.axes: - ax.tick_params(labelbottom=False, labelleft=False) +label_axes(ax4, "nx=2, nx1=4, ny=0") plt.show()
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: