From 438485fc41dbb7c0c1b711293d2ec08f52bbb79e Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 25 Apr 2021 15:04:33 +0200 Subject: [PATCH] Improve labeling in simple_axes_divider1 example. --- examples/axes_grid1/simple_axes_divider1.py | 25 +++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) 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() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy