Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Artist class contains Abstract base class for objects that render into a FigureCanvas. All visible elements in a figure are subclasses of Artist.
Matplotlib.artist.Artist.get_children() Method
The get_children() method in artist module of matplotlib library is used to return a list of the child Artists of this Artist.
Syntax: Artist.get_children(self)
Parameters: This method does not accept any parameters.
Returns: This method return a list of the child Artists of this Artist.
Below examples illustrate the matplotlib.artist.Artist.get_children() function in matplotlib:
Example 1:
# Implementation of matplotlib function from matplotlib.artist import Artist import matplotlib.pyplot as plt from matplotlib.lines import Line2D import numpy as np from numpy.random import rand fig, ax2 = plt.subplots() art = ax2.bar( range ( 10 ), rand( 10 ), picker = True ) print ( "List of the child Artists of this Artist \n" , * list (art.get_children()), sep = "\n" ) plt.title( """matplotlib.artist.Artist.get_children() function Example""" , fontweight = "bold") plt.show() |
Output:
List of the child Artists of this Artist Rectangle(xy=(-0.4, 0), width=0.8, height=0.58236, angle=0) Rectangle(xy=(0.6, 0), width=0.8, height=0.305497, angle=0) Rectangle(xy=(1.6, 0), width=0.8, height=0.650615, angle=0) Rectangle(xy=(2.6, 0), width=0.8, height=0.397435, angle=0) Rectangle(xy=(3.6, 0), width=0.8, height=0.634406, angle=0) Rectangle(xy=(4.6, 0), width=0.8, height=0.377936, angle=0) Rectangle(xy=(5.6, 0), width=0.8, height=0.229145, angle=0) Rectangle(xy=(6.6, 0), width=0.8, height=0.755452, angle=0) Rectangle(xy=(7.6, 0), width=0.8, height=0.954083, angle=0) Rectangle(xy=(8.6, 0), width=0.8, height=0.509706, angle=0)
Example 2:
# Implementation of matplotlib function from matplotlib.artist import Artist import matplotlib.pyplot as plt import numpy as np from matplotlib.patches import Ellipse NUM = 20 ells = [Ellipse(xy = np.random.rand( 2 ) * 10 , 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' }) print ( "List of the child Artists of this Artist \n" ) for e in ells: ax.add_artist(e) e.set_clip_box(ax.bbox) e.set_alpha(np.random.rand()) e.set_facecolor(np.random.rand( 4 )) print ( * list (ax.get_children()), sep = "\n" ) ax.set_xlim( 3 , 7 ) ax.set_ylim( 3 , 7 ) plt.title( """matplotlib.artist.Artist.get_children() function Example""" , fontweight = "bold") plt.show() |
Output:
List of the child Artists of this Artist
Ellipse(xy=(4.326855439698613, 2.7591364805447203), width=0.3769330255888693, height=0.09156791653641638, angle=214.69480533893034)
Ellipse(xy=(6.390844512455681, 9.892865008928519), width=0.9788647690898709, height=0.006285544366887663, angle=19.48625036621184)
Ellipse(xy=(3.8942483639049827, 4.287056910903157), width=0.606133047296441, height=0.617384417649593, angle=20.0397376329806)
Ellipse(xy=(3.630783397391164, 0.01600429191145447), width=0.5132343441485764, height=0.3223079313175885, angle=245.01705091542485)
Ellipse(xy=(6.642450434821133, 1.8908827697887387), width=0.23993395257701733, height=0.3765935149323739, angle=110.92437831051637)
Ellipse(xy=(6.920276912378068, 5.377803276288121), width=0.5386745526104751, height=0.41537451864828756, angle=142.07394163562782)
Ellipse(xy=(1.9677674418882851, 2.387920020189397), width=0.9281624394894327, height=0.9254130366925344, angle=156.70467412886455)
Ellipse(xy=(0.2503405192644126, 9.617585928972508), width=0.3325457173919193, height=0.5376108963426213, angle=115.82961034724622)
Ellipse(xy=(2.740648631358077, 4.848712686784504), width=0.33431953219674915, height=0.15600420830752393, angle=187.6988500178232)
Ellipse(xy=(7.817150974564463, 0.49404863554939893), width=0.6762860795951, height=0.33199673269913654, angle=24.531338409068965)
Ellipse(xy=(4.405895252381874, 8.971532666413125), width=0.323530322681283, height=0.17015118100996518, angle=51.63377527727279)
Ellipse(xy=(2.0866009844129363, 0.2333848286892204), width=0.9709589782658046, height=0.3899245224635858, angle=111.49829657493017)
Ellipse(xy=(3.393463178402535, 1.745800383006476), width=0.910150361558863, height=0.9610855341570913, angle=21.59396958380354)
Ellipse(xy=(6.184415601545293, 3.5307798535485704), width=0.15464027865711882, height=0.3251963397808111, angle=131.180626549346)
Ellipse(xy=(6.719146468170946, 3.6360516066867032), width=0.7501942033899773, height=0.43431493522372855, angle=169.094548362262)
Ellipse(xy=(7.506012347492045, 3.1516316232445654), width=0.4659708340454164, height=0.7493110856158617, angle=73.832677168027)
Ellipse(xy=(3.4633685651536297, 1.9748873150243362), width=0.7861860502801421, height=0.0017214411684519648, angle=233.57282481274447)
Ellipse(xy=(6.999249808517529, 6.225733934196579), width=0.128202506956425, height=0.2630581946193207, angle=118.40966593942818)
Ellipse(xy=(2.299424739635106, 4.016364131220095), width=0.1284216985742045, height=0.7005169718502383, angle=103.98855209070578)
Ellipse(xy=(3.4547392780288453, 7.279383257684645), width=0.12553381689327947, height=0.3564243545207635, angle=215.19335067931772)
Spine
Spine
Spine
Spine
XAxis(54.0,36.0)
YAxis(54.0,36.0)
Text(0.5, 1.0, ”)
Text(0.0, 1.0, ”)
Text(1.0, 1.0, ”)
Rectangle(xy=(0, 0), width=1, height=1, angle=0)