Skip to content

Commit f7c4bb0

Browse files
committed
Add test for axis label when units set
Fix indentation
1 parent dc163ca commit f7c4bb0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/matplotlib/testing/jpl_units/UnitDbl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def __bool__(self):
9191

9292
def _cmp(self, op, rhs):
9393
"""Check that *self* and *rhs* share units; compare them using *op*."""
94+
if rhs is None:
95+
return NotImplemented
9496
self.checkSameUnits(rhs, "compare")
9597
return op(self._value, rhs._value)
9698

lib/matplotlib/tests/test_units.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,23 @@ def test_plot_kernel():
283283
# just a smoketest that fail
284284
kernel = Kernel([1, 2, 3, 4, 5])
285285
plt.plot(kernel)
286+
287+
288+
@check_figures_equal(extensions=['png'])
289+
def test_unit_axis_label(fig_test, fig_ref):
290+
import matplotlib.testing.jpl_units as units
291+
units.register()
292+
293+
data = [0 * units.km, 1 * units.km, 2 * units.km]
294+
295+
ax_test = fig_test.subplots()
296+
ax_ref = fig_ref.subplots()
297+
axs = [ax_test, ax_ref]
298+
299+
for ax in axs:
300+
ax.yaxis.set_units('km')
301+
ax.set_xlim(10, 20)
302+
ax.set_ylim(10, 20)
303+
304+
ax_test.scatter([1, 2, 3], data, edgecolors='none')
305+
ax_ref.plot([1, 2, 3], data, marker='o', linewidth=0)

0 commit comments

Comments
 (0)