Module plottools.aspect

Adapting plots to aspect ratio of axes.

Axes member functions

Install/uninstall aspect functions

You usually do not need to call these functions. Upon loading the aspect module, install_aspect() is called automatically.

Functions

def aspect_ratio(ax)

Aspect ratio of axes.

Parameters

ax : matplotlib axes
Axes of which aspect ratio is computed.

Returns

aspect : float
Aspect ratio (height in inches relative to width).
def set_xlim_equal(ax, xmin_frac=0.0, xmax_frac=1.0)

Ensure equal aspect ratio by appropriately setting x limits.

If you need both axis equally scaled, such that on the plot a unit on the x-axis covers the same distance as a unit on the y-axis, one usually calls ax.set_aspect('equal'). This mechanism scales the physical dimensions of the plot to make the units on both axis equal. Problem is, that then the physical dimensions of the plot differ from other plots in the grid.

The set_xlim_equal() function uses a different approach. Instead of scaling the physical dimensions of the plot, the limits of the x-axis are adapted to the aspect-ratio of the full plot. This way the dimensions of the plot are not scaled.

Call this function after setting the limits of the x-axis.

Parameters

ax : matplotlib axes
Axes of which aspect ratio is computed.
xmin_frac : float
Fraction of the total range of the x-axis for the minimum value of the x-axis.
xmax_frac : float
Fraction of the total range of the x-axis for the maximum value of the x-axis.

See Also

set_ylim_equal(), aspect_ratio()

def set_ylim_equal(ax, ymin_frac=0.0, ymax_frac=1.0)

Ensure equal aspect ratio by appropriately setting y limits.

If you need both axis equally scaled, such that on the plot a unit on the x-axis covers the same distance as a unit on the y-axis, one usually calls ax.set_aspect('equal'). This mechanism scales the physical dimensions of the plot to make the units on both axis equal. Problem is, that then the physical dimensions of the plot differ from other plots in the grid.

The set_ylim_equal() function uses a different approach. Instead of scaling the physical dimensions of the plot, the limits of the y-axis are adapted to the aspect-ratio of the full plot. This way the dimensions of the plot are not scaled.

Call this function after setting the limits of the x-axis.

Parameters

ax : matplotlib axes
Axes of which aspect ratio is computed.
ymin_frac : float
Fraction of the total range of the y-axis for the minimum value of the y-axis.
ymax_frac : float
Fraction of the total range of the y-axis for the maximum value of the y-axis.

See Also

set_xlim_equal(), aspect_ratio()

def install_aspect()

Install functions of the aspect module in matplotlib.

See Also

uninstall_aspect()

def uninstall_aspect()

Uninstall all code of the aspect module from matplotlib.

See Also

install_aspect()

def demo()

Run a demonstration of the aspect module.