|
4 | 4 |
|
5 | 5 | from nose.tools import assert_equal
|
6 | 6 | import numpy as np
|
7 |
| -from numpy.testing import assert_array_equal |
| 7 | +from numpy.testing import assert_array_equal, assert_array_almost_equal |
8 | 8 |
|
9 | 9 | import matplotlib.pyplot as plt
|
10 | 10 | import matplotlib.collections as mcollections
|
@@ -396,9 +396,49 @@ def test_null_collection_datalim():
|
396 | 396 | col = mcollections.PathCollection([])
|
397 | 397 | col_data_lim = col.get_datalim(mtransforms.IdentityTransform())
|
398 | 398 | assert_array_equal(col_data_lim.get_points(),
|
399 |
| - mtransforms.Bbox([[0, 0], [0, 0]]).get_points()) |
| 399 | + mtransforms.Bbox.null().get_points()) |
400 | 400 |
|
401 | 401 |
|
| 402 | +@cleanup |
| 403 | +def test_add_collection(): |
| 404 | + # Test if data limits are unchanged by adding an empty collection. |
| 405 | + # Github issue #1490, pull #1497. |
| 406 | + ax = plt.axes() |
| 407 | + plt.figure() |
| 408 | + ax2 = plt.axes() |
| 409 | + coll = ax2.scatter([0, 1], [0, 1]) |
| 410 | + ax.add_collection(coll) |
| 411 | + bounds = ax.dataLim.bounds |
| 412 | + coll = ax2.scatter([], []) |
| 413 | + ax.add_collection(coll) |
| 414 | + assert_equal(ax.dataLim.bounds, bounds) |
| 415 | + |
| 416 | + |
| 417 | +@cleanup |
| 418 | +def test_quiver_limits(): |
| 419 | + ax = plt.axes() |
| 420 | + x = np.linspace(-5, 10, 20) |
| 421 | + y = np.linspace(-2, 4, 10) |
| 422 | + y, x = np.meshgrid(y, x) |
| 423 | + trans = mtransforms.Affine2D().translate(25, 32) + ax.transData |
| 424 | + plt.quiver(x, y, np.sin(x), np.cos(y), transform=trans) |
| 425 | + assert_equal(ax.dataLim.bounds, (20.0, 30.0, 15.0, 6.0)) |
| 426 | + |
| 427 | + |
| 428 | +@cleanup |
| 429 | +def test_barb_limits(): |
| 430 | + ax = plt.axes() |
| 431 | + x = np.linspace(-5, 10, 20) |
| 432 | + y = np.linspace(-2, 4, 10) |
| 433 | + y, x = np.meshgrid(y, x) |
| 434 | + trans = mtransforms.Affine2D().translate(25, 32) + ax.transData |
| 435 | + plt.barbs(x, y, np.sin(x), np.cos(y), transform=trans) |
| 436 | + # The calculated bounds are approximately the bounds of the original data, |
| 437 | + # this is because the entire path is taken into account when updating the |
| 438 | + # datalim. |
| 439 | + assert_array_almost_equal(ax.dataLim.bounds, (20, 30, 15, 6), |
| 440 | + decimal=2) |
| 441 | + |
402 | 442 | if __name__ == '__main__':
|
403 | 443 | import nose
|
404 | 444 | nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
|
0 commit comments