Open In App

Matplotlib.axis.Axis.get_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.get_smart_bounds() Function

The Axis.get_smart_bounds() function in axis module of matplotlib library is used to get whether the axis has smart bounds. 
 



Syntax: Axis.get_smart_bounds(self) 
 

Parameters: This method does not accepts any parameters. 
 



Return value: This method return whether the axis has smart bounds. 

Below examples illustrate the matplotlib.axis.Axis.get_smart_bounds() function in matplotlib.axis:
 

Example 1:




# 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.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
   
ax.grid()
  
print("Value return by get_smart_bounds() : [",
      ax.xaxis.get_smart_bounds(),
      ax.yaxis.get_smart_bounds(),"]")
  
fig.suptitle("""matplotlib.axis.Axis.get_smart_bounds()
function Example\n""", fontweight ="bold")  
    
plt.show()

Output: 
 

Value return by get_smart_bounds() : [ False False ]

Example 2:




# 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()
  
print("Value return by get_smart_bounds() :"
      ax.xaxis.get_smart_bounds())
  
fig.suptitle("""matplotlib.axis.Axis.get_smart_bounds()
function Example\n""", fontweight ="bold")  
    
plt.show()

Output: 
 

Value return by get_smart_bounds() : True

 


Article Tags :