Matplotlib.axis.Axis.set_smart_bounds() function in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. It is an amazing visualization library in Python for 2D plots of arrays and used for working with the broader SciPy stack.
Matplotlib.axis.Axis.set_smart_bounds() Function
The Axis.set_smart_bounds() function in axis module of matplotlib library is used to set the axis to have smart bounds.
Syntax: Axis.set_smart_bounds(self, value)
Parameters: This method accepts the following parameters.
- value: This parameter is the bool value.
Return value: This method does not return any value.
Below examples illustrate the matplotlib.axis.Axis.set_smart_bounds() function in matplotlib.axis:
Example 1:
Python3
# Implementation of matplotlib functionfrom matplotlib.axis import Axisimport numpy as npimport matplotlib.pyplot as plt fig = plt.figure()x = np.linspace(-np.pi, np.pi, 100)y = 2*np.sin(x) ax = fig.add_subplot()ax.set_title('centered spines')ax.plot(x, y) ax.spines['left'].set_position('center')ax.spines['right'].set_color('none')ax.spines['bottom'].set_position('center')ax.spines['top'].set_color('none')ax.spines['left'].set_smart_bounds(True)ax.spines['bottom'].set_smart_bounds(True) ax.xaxis.set_ticks_position('bottom')ax.yaxis.set_ticks_position('left') ax.grid() fig.suptitle("""matplotlib.axis.Axis.set_smart_bounds()function Example\n""", fontweight ="bold") plt.show() |
Output:

Example 2:
Python3
# Implementation of matplotlib functionfrom matplotlib.axis import Axisimport numpy as npimport matplotlib.pyplot as plt fig = plt.figure()x = np.linspace(-np.pi, np.pi, 100)y = 2*np.sin(x) ax = fig.add_subplot()ax.set_title('Spines at data (3, 2)')ax.plot(x, y) ax.spines['left'].set_position(('data', 3))ax.spines['right'].set_color('none')ax.spines['bottom'].set_position(('data', 2))ax.spines['top'].set_color('none')ax.spines['left'].set_smart_bounds(True)ax.spines['bottom'].set_smart_bounds(True) ax.xaxis.set_ticks_position('bottom')ax.yaxis.set_ticks_position('left') ax.grid() fig.suptitle("""matplotlib.axis.Axis.set_smart_bounds()function Example\n""", fontweight ="bold") plt.show() |
Output:

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course


