Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fb76ed7

Browse filesBrowse files
committed
Add test for datetime and categorical
1 parent 6d54d3a commit fb76ed7
Copy full SHA for fb76ed7

File tree

Expand file treeCollapse file tree

1 file changed

+16
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-1
lines changed

‎lib/matplotlib/tests/test_units.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_units.py
+16-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.