Wednesday, July 3, 2024
HomeLanguagesPythonMatplotlib.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:Ā 

Ā 

Ted Musemwa
As a software developer Iā€™m interested in the intersection of computational thinking and design thinking when solving human problems. As a professional I am guided by the principles of experiential learning; experience, reflect, conceptualise and experiment.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments