Matplotlib.axes.Axes.margins() in Python Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. matplotlib.axes.Axes.margins() Function The Axes.margins() function in axes module of matplotlib library is used to set or retrieve autoscaling margins. Syntax: Axes.margins(self, *margins, x=None, y=None, tight=True)Parameters: This method accepts the following parameters. *margins: This parameter is used to specify both margins of the x-axis and y-axis limits.x, y: These parameter is used to specific margin values for the x-axis and y-axis, respectively.tight : This parameter is passed to autoscale_view(), which is executed after a margin is changed. Return value: The following values are returned by this method. xmarginymargin Below examples illustrate the matplotlib.axes.Axes.margins() function in matplotlib.axes:Example 1: Python3 # Implementation of matplotlib function import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Slider, Button, RadioButtons fig, (ax, ax1) = plt.subplots(1, 2) plt.subplots_adjust(bottom = 0.25) t = np.arange(0.0, 1.0, 0.001) a0 = 5 f0 = 3 delta_f = 5.0 s = a0 * np.sin(2 * np.pi * f0 * t) ax.plot(t, s, lw = 2, color = 'green') ax1.plot(t, s, lw = 2, color = 'green') ax1.margins(0.5) ax.set_title("Without margin() Function") ax1.set_title("With margin value = 0") fig.suptitle('matplotlib.axes.Axes.margins() function \ Example\n', fontweight ="bold") fig.canvas.draw() plt.show() Output: Example 2: Python3 # Implementation of matplotlib function import numpy as np import matplotlib.pyplot as plt t = np.arange(0.0, 3.0, 0.01) t1 = np.exp(-t) * np.cos(2 * np.pi * t) fig, [ax1, ax2, ax3] = plt.subplots(nrows = 3) ax1.plot(t, t1, color ="green") ax1.text(1.1, 0.65, 'Original window') ax2.margins(2, 2) ax2.plot(t, t1, color ="green") ax2.text(0, 2.0, 'Zoomed out') ax3.margins(x = 0, y =-0.25) ax3.plot(t, t1, color ="green") ax3.text(1.2, 0.35, 'Zoomed in') fig.suptitle('matplotlib.axes.Axes.margins() function\ Example\n', fontweight ="bold") fig.canvas.draw() plt.show() Output: Comment More infoAdvertise with us Next Article Matplotlib.axes.Axes.axis() in Python S SHUBHAMSINGH10 Follow Improve Article Tags : Python Python-matplotlib Practice Tags : python Similar Reads Matplotlib.axes.Axes.grid() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Matplotlib.axes.Axes.axis() in Python The Axes.axis() function in Matplotlib is used to get or set the properties of the x-axis and y-axis limits on a given Axes object. It provides an easy way to control the view limits, aspect ratio, and visibility of the axes in a plot. It's key feature include:Get the current axis limits as [xmin, x 2 min read Matplotlib.axes.Axes.get_lines() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Matplotlib.axes.Axes.axvline() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Matplotlib.axes.Axes.inset_axes() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Matplotlib.axes.Axes.bxp() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 3 min read Like