Skip to content
Related Articles

Related Articles

Matplotlib.figure.Figure.draw_artist() in Python

Improve Article
Save Article
  • Last Updated : 30 Apr, 2020
Improve Article
Save Article

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements.

matplotlib.figure.Figure.draw_artist() function

The draw_artist() method of figure module of matplotlib library is used to draw matplotlib.artist.Artist instance a only.

Syntax: draw_artist(self, a)

Parameters: This accept the following parameters that are described below:

  • a: This parameter is the artist.

Returns: This method does not return any value.

Below examples illustrate the matplotlib.figure.Figure.draw_artist() function in matplotlib.figure:

Example 1:

# Implementation of matplotlib function 
from random import randint, choice
import time
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
back_color = "black"
colors = ['red', 'green', 'blue', 'purple']
width, height = 4, 4
fig, ax = plt.subplots()
ax.set(xlim =[0, width], ylim =[0, height])
def update():
    x = randint(0, width - 1)
    y = randint(0, height - 1)
    arti = mpatches.Rectangle(
        (x, y), 1, 1,
        facecolor = choice(colors),
        edgecolor = back_color
    start = time.time()
    print("Draw at time :", time.time() - start)
timer = fig.canvas.new_timer(interval = 1)
fig.suptitle('matplotlib.figure.Figure.draw_artist() \
function Example')


Draw at time : 0.2968637943267822
Draw at time : 0.031249523162841797
Draw at time : 0.015642404556274414
Draw at time : 0.015624523162841797
Draw at time : 0.015607357025146484
Draw at time : 0.015637636184692383
so on.

Example 2:

# Implementation of matplotlib function 
import matplotlib.pyplot as plt
import numpy as np
import time
fig, ax = plt.subplots()
line, = ax.plot(np.random.randn(100))
tstart = time.time()
num_plots = 0
while time.time()-tstart < 5:
    num_plots += 1
 function Example')


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!