# 7 examples of 'matplotlib equal axis' in Python

Every line of 'matplotlib equal axis' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure. ## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``10def set_axes_equal(ax):11    '''Make axes of 3D plot have equal scale so that spheres appear as spheres,12    cubes as cubes, etc..  This is one possible solution to Matplotlib's13    ax.set_aspect('equal') and ax.axis('equal') not working for 3D.1415    Input16      ax: a matplotlib axis, e.g., as output from plt.gca().17    '''1819    x_limits = ax.get_xlim3d()20    y_limits = ax.get_ylim3d()21    z_limits = ax.get_zlim3d()2223    x_range = abs(x_limits - x_limits)24    x_middle = np.mean(x_limits)25    y_range = abs(y_limits - y_limits)26    y_middle = np.mean(y_limits)27    z_range = abs(z_limits - z_limits)28    z_middle = np.mean(z_limits)2930    # The plot bounding box is a sphere in the sense of the infinity31    # norm, hence I call half the max range the plot radius.32    plot_radius = 0.5*max([x_range, y_range, z_range])3334    ax.set_xlim3d([x_middle - plot_radius, x_middle + plot_radius])35    ax.set_ylim3d([y_middle - plot_radius, y_middle + plot_radius])36    ax.set_zlim3d([z_middle - plot_radius, z_middle + plot_radius])``
``104def setup_axis(X, Y, ax=None, fig=None, ylims=None):105    """Setup axis, including timer for animation or snaps106107    Parameters108    ----------109    X :110        space disctretization to get limits111    Y :112        solution to get limits113    ax :114        ax where to put everything, if None current axes are used (Default value = None)115    fig :116        fig where to put everything, if None current figure is used (Default value = None)117    ylims :118        custom ylims, if None y axis limits are calculated from Y (Default value = None)119120    Returns121    -------122    ax123124    fig125126    time_text127        object to fill in text128129    """130    if ax is None:131        fig = plt.gcf()132        ax = plt.gca()133    if ylims is None:134        lowery = nm.min(Y) - nm.min(Y) / 10135        uppery = nm.max(Y) + nm.max(Y) / 10136    else:137        lowery = ylims138        uppery = ylims139    ax.set_ylim(lowery, uppery)140    ax.set_xlim(X, X[-1])141    time_text = ax.text(X + nm.sign(X) * X / 10,142                        uppery - uppery / 10,143                        'empty', fontsize=15)144    return ax, fig, time_text``
``20def square_axis(axes=None):21  """22  Expands the x- and y-limits on the given axes so that they are equal23  (defaults to the current axes).24  """25  if axes is None:26    axes = gca()27  tmpv = axes.axis()28  xmax = max([tmpv, tmpv])29  xmin = min([tmpv, tmpv])30  axes.axis([xmin, xmax, xmin, xmax])``
``327def draw_axes3(self, *args, **kwargs):328    """ Graphics package draw plot axes for 3D space.329    """ 330    print("* Not yet implemented.")331    return None``
``396def set_default_locators_and_formatters(self, axis):397    """398    Set the locators and formatters to specialized versions for399    symmetrical log scaling.400    """401    axis.set_major_locator(SymmetricalLogLocator(self.get_transform()))402    axis.set_major_formatter(LogFormatterMathtext(self.base))403    axis.set_minor_locator(SymmetricalLogLocator(self.get_transform(), self.subs))404    axis.set_minor_formatter(NullFormatter())``
``372def set_axis_labels ( self , x ) :373    pass``
``87@staticmethod88def set_axes_equal(ax):89    """ Sets equal aspect ratio across the three axes of a 3D plot.9091    Contributed by Xuefeng Zhao.9293    :param ax: a Matplotlib axis, e.g., as output from plt.gca().94    """95    bounds = [ax.get_xlim3d(), ax.get_ylim3d(), ax.get_zlim3d()]96    ranges = [abs(bound - bound) for bound in bounds]97    centers = [np.mean(bound) for bound in bounds]98    radius = 0.5 * max(ranges)99    lower_limits = centers - radius100    upper_limits = centers + radius101    ax.set_xlim3d([lower_limits, upper_limits])102    ax.set_ylim3d([lower_limits, upper_limits])103    ax.set_zlim3d([lower_limits, upper_limits])``