Of the docs, aspect ratio is the ratio of data scaling units to the display in the x and y axes. that is, if there are 10 data units and 1 unit of data per display unit in the x direction on the display in y units, this ratio will be 1/10. The circle will be 10 times wider than tall. This is consistent with the statement that the num aspect does the following:
the circle will be stretched so that the height is several times larger than the width. aspect = 1 matches aspect = equal.
Based on the same original code snippet you were looking at ( matplotlib.axes._base.adjust_aspect starting at line 1405 ), I think we can come up with a simplified formula if you only need this ratio for linear Cartesian axes. Everything is complicated by polar and logarithmic axes, so I will ignore them.
Repeat formula:
(x_data_unit / x_display_unit) / (y_data_unit / y_display_unit)
It happens the same way
(y_display_unit / x_display_unit) / (y_data_unit / x_data_unit)
This last statement is simply the ratio of the dimensions of the display in two directions divided by the ratio of the limits x and y. Note that ax.get_data_ratio NOT applied here because it returns results for actual data boundaries, not axis limits:
from operator import sub def get_aspect(ax):
Now let's test it:
from matplotlib import pyplot as plt fig, ax = plt.subplots() ax.set_aspect('equal') print('{} == {}'.format(ax.get_aspect(), get_aspect(ax))) ax.set_aspect(10) print('{} == {}'.format(ax.get_aspect(), get_aspect(ax)))
Mad physicist
source share