|
1 | 1 | import matplotlib.pyplot as plt
|
| 2 | +from matplotlib.testing.decorators import image_comparison |
2 | 3 | import matplotlib.units as munits
|
3 | 4 | import numpy as np
|
4 | 5 |
|
|
9 | 10 | from mock import MagicMock
|
10 | 11 |
|
11 | 12 |
|
12 |
| -# Tests that the conversion machinery works properly for classes that |
13 |
| -# work as a facade over numpy arrays (like pint) |
14 |
| -def test_numpy_facade(): |
15 |
| - # Basic class that wraps numpy array and has units |
16 |
| - class Quantity(object): |
17 |
| - def __init__(self, data, units): |
18 |
| - self.magnitude = data |
19 |
| - self.units = units |
| 13 | +# Basic class that wraps numpy array and has units |
| 14 | +class Quantity(object): |
| 15 | + def __init__(self, data, units): |
| 16 | + self.magnitude = data |
| 17 | + self.units = units |
20 | 18 |
|
21 |
| - def to(self, new_units): |
22 |
| - return Quantity(self.magnitude, new_units) |
| 19 | + def to(self, new_units): |
| 20 | + return Quantity(self.magnitude, new_units) |
23 | 21 |
|
24 |
| - def __getattr__(self, attr): |
25 |
| - return getattr(self.magnitude, attr) |
| 22 | + def __getattr__(self, attr): |
| 23 | + return getattr(self.magnitude, attr) |
26 | 24 |
|
27 |
| - def __getitem__(self, item): |
28 |
| - return self.magnitude[item] |
| 25 | + def __getitem__(self, item): |
| 26 | + return self.magnitude[item] |
29 | 27 |
|
| 28 | + |
| 29 | +# Tests that the conversion machinery works properly for classes that |
| 30 | +# work as a facade over numpy arrays (like pint) |
| 31 | +def test_numpy_facade(): |
30 | 32 | # Create an instance of the conversion interface and
|
31 | 33 | # mock so we can check methods called
|
32 | 34 | qc = munits.ConversionInterface()
|
@@ -55,3 +57,15 @@ def convert(value, unit, axis):
|
55 | 57 | assert qc.convert.called
|
56 | 58 | assert qc.axisinfo.called
|
57 | 59 | assert qc.default_units.called
|
| 60 | + |
| 61 | + |
| 62 | +# Tests gh-8908 |
| 63 | +@image_comparison(baseline_images=['plot_masked_units'], |
| 64 | + extensions=['png'], remove_text=True, style='mpl20') |
| 65 | +def test_plot_masked_units(): |
| 66 | + data = np.linspace(-5, 5) |
| 67 | + data_masked = np.ma.array(data, mask=(data > -2) & (data < 2)) |
| 68 | + data_masked_units = Quantity(data_masked, 'meters') |
| 69 | + |
| 70 | + fig, ax = plt.subplots() |
| 71 | + ax.plot(data_masked_units) |
0 commit comments