Thursday, July 4, 2024
HomeLanguagesPythonMatplotlib.axis.Tick.set_clip_box() function in Python

Matplotlib.axis.Tick.set_clip_box() 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.Tick.set_clip_box() Function

The Tick.set_clip_box() function in axis module of matplotlib library is used to set the artistā€™s clip Bbox.Ā 
Ā 

Syntax: Tick.set_clip_box(self, clipbox)Ā 
Ā 

Parameters: This method accepts the following parameters.Ā 

  • clipbox: This parameter is the Bbox.

Return value: This method does not return any value.Ā 

Below examples illustrate the matplotlib.axis.Tick.set_clip_box() function in matplotlib.axis:
Example 1:

Python3




# Implementation of matplotlib function
from matplotlib.axis import Tick
import matplotlib.pyplot as pltĀ Ā 
import numpy as npĀ Ā 
from matplotlib.patches import EllipseĀ Ā 
Ā Ā Ā Ā Ā Ā Ā 
Ā Ā Ā Ā Ā 
delta = 10.0
Ā Ā Ā Ā Ā Ā Ā 
angles = np.arange(0, 360 + delta, delta)Ā Ā 
ells = [Ellipse((2, 2), 5, 2, a) for a in angles]Ā Ā 
Ā Ā Ā Ā Ā Ā Ā 
fig, ax = plt.subplots()Ā Ā 
Ā Ā Ā Ā Ā Ā Ā 
for e in ells:Ā Ā 
Ā Ā Ā Ā Tick.set_clip_box(e, ax.bbox)Ā Ā 
Ā Ā Ā Ā e.set_alpha(0.1)Ā Ā 
Ā Ā Ā Ā ax.add_artist(e)Ā Ā 
Ā Ā Ā Ā Ā Ā Ā 
plt.xlim(-1, 5)Ā Ā 
plt.ylim(-1, 5)Ā 
Ā Ā 
fig.suptitle('matplotlib.axis.Tick.set_clip_box() \
function Example', fontweight ="bold")Ā Ā 
Ā Ā Ā Ā Ā 
plt.show()Ā 
=


Output:Ā 

Example 2:

Python3




# Implementation of matplotlib function
from matplotlib.axis import Tick
import matplotlib.pyplot as pltĀ Ā 
import numpy as npĀ Ā 
from matplotlib.patches import EllipseĀ Ā 
Ā Ā Ā Ā Ā Ā Ā Ā Ā 
Ā Ā Ā Ā Ā 
NUM = 200
Ā Ā Ā Ā Ā Ā Ā Ā Ā 
ells = [Ellipse(xy = np.random.rand(2),Ā Ā 
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā width = np.random.rand(),Ā Ā Ā 
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā height = np.random.rand(),Ā Ā 
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā angle = np.random.rand() * 360)Ā Ā 
Ā Ā Ā Ā Ā Ā Ā Ā for i in range(NUM)]Ā Ā 
Ā Ā Ā Ā Ā Ā Ā Ā Ā 
fig, ax = plt.subplots(subplot_kw ={'aspect': 'equal'})Ā Ā 
Ā Ā Ā Ā Ā 
for e in ells:Ā Ā 
Ā Ā Ā Ā ax.add_artist(e)Ā 
Ā Ā Ā Ā Tick.set_clip_box(e, ax.bbox)Ā Ā 
Ā Ā Ā Ā e.set_clip_box(ax.bbox)Ā Ā 
Ā Ā Ā Ā e.set_alpha(np.random.rand())Ā Ā 
Ā Ā Ā Ā e.set_facecolor(np.random.rand(4))Ā Ā 
Ā Ā 
fig.suptitle('matplotlib.axis.Tick.set_clip_box() \
function Example', fontweight ="bold")Ā Ā 
Ā Ā Ā Ā Ā 
plt.show()Ā 


Output:Ā 

Ā 

Thapelo Manthata
Iā€™m a desktop support specialist transitioning into a SharePoint developer role by day and Software Engineering student by night. My superpowers include customer service, coding, the Microsoft office 365 suite including SharePoint and power platform.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments