|
2 | 2 | unicode_literals)
|
3 | 3 |
|
4 | 4 | from matplotlib.externals import six
|
| 5 | +import sys |
| 6 | +import io |
| 7 | +import os |
5 | 8 |
|
6 | 9 | import numpy as np
|
7 | 10 |
|
8 |
| -from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup |
| 11 | +from matplotlib.testing.decorators import (image_comparison, |
| 12 | + knownfailureif, cleanup) |
9 | 13 | from matplotlib.image import BboxImage, imread, NonUniformImage
|
10 | 14 | from matplotlib.transforms import Bbox
|
11 | 15 | from matplotlib import rcParams
|
12 | 16 | import matplotlib.pyplot as plt
|
13 |
| -from nose.tools import assert_raises |
14 |
| -from numpy.testing import assert_array_equal, assert_array_almost_equal |
15 | 17 |
|
16 |
| -import io |
17 |
| -import os |
| 18 | +from numpy.testing import assert_array_equal |
| 19 | + |
| 20 | + |
| 21 | +import nose |
18 | 22 |
|
19 | 23 | try:
|
20 | 24 | from PIL import Image
|
| 25 | + del Image |
21 | 26 | HAS_PIL = True
|
22 | 27 | except ImportError:
|
23 | 28 | HAS_PIL = False
|
24 | 29 |
|
| 30 | + |
25 | 31 | @image_comparison(baseline_images=['image_interps'])
|
26 | 32 | def test_image_interps():
|
27 | 33 | 'make the basic nearest, bilinear and bicubic interps'
|
@@ -447,12 +453,52 @@ def test_nonuniformimage_setcmap():
|
447 | 453 | im = NonUniformImage(ax)
|
448 | 454 | im.set_cmap('Blues')
|
449 | 455 |
|
| 456 | + |
450 | 457 | @cleanup
|
451 | 458 | def test_nonuniformimage_setnorm():
|
452 | 459 | ax = plt.gca()
|
453 | 460 | im = NonUniformImage(ax)
|
454 | 461 | im.set_norm(plt.Normalize())
|
455 | 462 |
|
| 463 | + |
| 464 | +@cleanup |
| 465 | +def test_minimized_rasterized(): |
| 466 | + # This ensures that the rasterized content in the colorbars is |
| 467 | + # only as thick as the colorbar, and doesn't extend to other parts |
| 468 | + # of the image. See #5814. While the original bug exists only |
| 469 | + # in Postscript, the best way to detect it is to generate SVG |
| 470 | + # and then parse the output to make sure the two colorbar images |
| 471 | + # are the same size. |
| 472 | + if sys.version_info[:2] < (2, 7): |
| 473 | + raise nose.SkipTest("xml.etree.ElementTree.Element.iter " |
| 474 | + "added in py 2.7") |
| 475 | + |
| 476 | + from xml.etree import ElementTree |
| 477 | + |
| 478 | + np.random.seed(0) |
| 479 | + data = np.random.rand(10, 10) |
| 480 | + |
| 481 | + fig, ax = plt.subplots(1, 2) |
| 482 | + p1 = ax[0].pcolormesh(data) |
| 483 | + p2 = ax[1].pcolormesh(data) |
| 484 | + |
| 485 | + plt.colorbar(p1, ax=ax[0]) |
| 486 | + plt.colorbar(p2, ax=ax[1]) |
| 487 | + |
| 488 | + buff = io.BytesIO() |
| 489 | + plt.savefig(buff, format='svg') |
| 490 | + |
| 491 | + buff = io.BytesIO(buff.getvalue()) |
| 492 | + tree = ElementTree.parse(buff) |
| 493 | + width = None |
| 494 | + for image in tree.iter('image'): |
| 495 | + if width is None: |
| 496 | + width = image['width'] |
| 497 | + else: |
| 498 | + if image['width'] != width: |
| 499 | + assert False |
| 500 | + |
| 501 | + |
456 | 502 | if __name__=='__main__':
|
457 | 503 | import nose
|
458 | 504 | nose.runmodule(argv=['-s','--with-doctest'], exit=False)
|
0 commit comments