Module plottools.aspect
Adapting plots to aspect ratio of axes.
Axes member functions
aspect_ratio()
: aspect ratio of axes.set_xlim_equal()
: ensure equal aspect ratio by appropriately setting x limits.set_ylim_equal()
: ensure equal aspect ratio by appropriately setting y limits.
Install/uninstall aspect functions
You usually do not need to call these functions. Upon loading the aspect
module, install_aspect()
is called automatically.
install_aspect()
: install functions of the aspect module in matplotlib.uninstall_aspect()
: uninstall all code of the aspect module from matplotlib.
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
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
def install_aspect()
def uninstall_aspect()
def demo()
-
Run a demonstration of the aspect module.