8000 Test blitting for matplotlib backends · GitHub
[go: up one dir, main page]

Skip to content

Instantly share code, notes, and snippets.

@spinnau
Created December 10, 2012 23:32
Show Gist options
  • Save spinnau/4254321 to your computer and use it in GitHub Desktop.
Save spinnau/4254321 to your computer and use it in GitHub Desktop.
Test blitting for matplotlib backends
# -*- coding: utf-8 -*-
from gi.repository import GObject
import matplotlib.pyplot as plt
from matplotlib.transforms import Bbox
from matplotlib.testing.compare import compare_images
import numpy as np
import subprocess
fig = plt.figure(0)
ax = fig.add_subplot(111)
canvas = fig.canvas
x = np.arange(0, 10, 0.1)
y = np.sin(x)
bbox = Bbox.from_bounds(0, 0, 10, 1)
background = canvas.copy_from_bbox(bbox)
line, = plt.plot(x, y, color='k')
def blit_test(*args):
""" Test backend's blit method """
# create reference screenshot for normal plot
if blit_test.n == 0:
subprocess.Popen(['import', '-window', 'Figure 0', 'ref.png'], stdout=subprocess.PIPE).communicate()
else:
canvas.restore_region(background)
ax.draw_artist(line)
canvas.blit(ax.bbox)
# create blitting screenshot and compare
if blit_test.n == 4:
subprocess.Popen(['import', '-window', 'Figure 0', 'blit.png'], stdout=subprocess.PIPE).communicate()
# some tolerance is needed, because plot line thickness is not exact
# the same during blitting
rms = compare_images('ref.png', 'blit.png', tol=1e-2)
if rms is None:
print('Test passed...')
else:
print('Test failed...')
plt.close()
blit_test.n += 1
return True
blit_test.n = 0
GObject.idle_add(blit_test)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
0