由于动态更新的性能问题,我需要在画布上直接绘制很多矩形作为非常低的级别,也就是说不使用matplotlib.patches,因为我们必须使用经典的GUI.
更准确地说,我想只绘制一个矩形,而不仅仅是所有的图形.
可能吗 ?
这是我使用Joe Kington给出的链接的测试代码.
#!/usr/bin/env python3
from random import randint, choice
import time
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.colors as colors
import matplotlib
back_color = "black"
colors = ['red', 'green', 'cyan', 'yellow']
width = 16
height = 16
ax = plt.subplot(111)
canvas = ax.figure.canvas
ax.set_xlim([0, width])
ax.set_ylim([0, height])
def update():
global ax, canvas, colors, width, height
x = randint(0, width - 1)
y = randint(0, height - 1)
rect = mpatches.Rectangle(
(x, y), 1, 1,