|
5 | 5 | from matplotlib.axes import Axes |
6 | 6 | import matplotlib.pyplot as plt |
7 | 7 | import matplotlib.category as cat |
| 8 | +from matplotlib.testing.decorators import check_figures_equal |
8 | 9 |
|
9 | 10 |
|
10 | 11 | class TestUnitData: |
@@ -269,3 +270,28 @@ def test_mixed_type_update_exception(self, ax, plotter, xdata): |
269 | 270 | with pytest.raises(TypeError): |
270 | 271 | plotter(ax, [0, 3], [1, 3]) |
271 | 272 | plotter(ax, xdata, [1, 2]) |
| 273 | + |
| 274 | + |
| 275 | +@pytest.mark.style('default') |
| 276 | +@check_figures_equal(extensions=["png"]) |
| 277 | +def test_overriding_units_in_plot(fig_test, fig_ref): |
| 278 | + from datetime import datetime |
| 279 | + |
| 280 | + t0 = datetime(2018, 3, 1) |
| 281 | + t1 = datetime(2018, 3, 2) |
| 282 | + t2 = datetime(2018, 3, 3) |
| 283 | + t3 = datetime(2018, 3, 4) |
| 284 | + |
| 285 | + ax_test = fig_test.subplots() |
| 286 | + ax_ref = fig_ref.subplots() |
| 287 | + for ax, kwargs in zip([ax_test, ax_ref], |
| 288 | + ({}, dict(xunits=None, yunits=None))): |
| 289 | + # First call works |
| 290 | + ax.plot([t0, t1], ["V1", "V2"], **kwargs) |
| 291 | + x_units = ax.xaxis.units |
| 292 | + y_units = ax.yaxis.units |
| 293 | + # this should not raise |
| 294 | + ax.plot([t2, t3], ["V1", "V2"], **kwargs) |
| 295 | + # assert that we have not re-set the units attribute at all |
| 296 | + assert x_units is ax.xaxis.units |
| 297 | + assert y_units is ax.yaxis.units |
0 commit comments