Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。 Figure模块提供了顶层Artist,即Figure,其中包含所有绘图元素。此模块用于控制所有图元的子图和顶层容器的默认间距。
matplotlib.figure.Figure.draw_artist()函数
matplotlib库的图形模块的draw_artist()方法仅用于绘制matplotlib.artist.Artist实例。
用法: draw_artist(self, a)
参数:这接受以下描述的以下参数:
- a:此参数是艺术家。
返回值:此方法不返回任何值。
以下示例说明了matplotlib.figure中的matplotlib.figure.Figure.draw_artist()函数:
范例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])
fig.canvas.draw()
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
)
ax.add_artist(arti)
start = time.time()
fig.draw_artist(arti)
fig.canvas.blit(ax.bbox)
print("Draw at time:", time.time() - start)
timer = fig.canvas.new_timer(interval = 1)
timer.add_callback(update)
timer.start()
fig.suptitle('matplotlib.figure.Figure.draw_artist() \
function Example')
plt.show()
输出:
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.
范例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
fig.canvas.draw()
while time.time()-tstart < 5:
line.set_ydata(np.random.randn(100))
fig.draw_artist(ax.patch)
fig.draw_artist(line)
num_plots += 1
fig.suptitle('matplotlib.figure.Figure.draw_artist()\
function Example')
plt.show()
输出:
相关用法
注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 Matplotlib.figure.Figure.draw_artist() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。