Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb76ed7

Browse files
committed
Add test for datetime and categorical
1 parent 6d54d3a commit fb76ed7

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/matplotlib/tests/test_units.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from datetime import datetime
1+
from datetime import datetime, timezone, timedelta
22
import platform
33
from unittest.mock import MagicMock
44

55
import matplotlib.pyplot as plt
66
from matplotlib.testing.decorators import check_figures_equal, image_comparison
77
import matplotlib.units as munits
8+
from matplotlib.category import UnitData
89
import numpy as np
910
import pytest
1011

@@ -188,3 +189,17 @@ def test_set_xyunits(quantity_converter):
188189
ax2.yaxis.set_units("inches")
189190
assert ax1.xaxis.get_units() == ax2.xaxis.get_units() == "seconds"
190191
assert ax1.yaxis.get_units() == ax2.yaxis.get_units() == "inches"
192+
y1 = [datetime(2020, i, 1, tzinfo=timezone.utc) for i in range(1, 13)]
193+
y2 = [datetime(2021, i, 1, tzinfo=timezone.utc) for i in range(1, 13)]
194+
fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
195+
ax1.plot(y1)
196+
ax2.plot(y2)
197+
ax1.yaxis.set_units(timezone(timedelta(hours=5)))
198+
assert ax2.yaxis.units == timezone(timedelta(hours=5))
199+
d1 = {"a": 1, "b": 2}
200+
d2 = {"a": 3, "b": 4}
201+
fig, (ax1, ax2) = plt.subplots(1, 2, sharex=True, sharey=True)
202+
ax1.plot(d1.keys(), d1.values())
203+
ax2.plot(d2.keys(), d2.values())
204+
ax1.xaxis.set_units(UnitData(["c", "d"]))
205+
assert "c" in ax2.xaxis.get_units()._mapping.keys()

0 commit comments

Comments
 (0)