Thursday, September 4, 2025
HomeLanguagesMatplotlib.axis.Axis.set_smart_bounds() function in Python

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 function
from matplotlib.axis import Axis
import numpy as np
import 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 function
from matplotlib.axis import Axis
import numpy as np
import 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: 

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS