|
1 |
| -from datetime import datetime |
| 1 | +from datetime import datetime, timezone, timedelta |
2 | 2 | import platform
|
3 | 3 | from unittest.mock import MagicMock
|
4 | 4 |
|
5 | 5 | import matplotlib.pyplot as plt
|
6 | 6 | from matplotlib.testing.decorators import check_figures_equal, image_comparison
|
7 | 7 | import matplotlib.units as munits
|
| 8 | +from matplotlib.category import UnitData |
8 | 9 | import numpy as np
|
9 | 10 | import pytest
|
10 | 11 |
|
@@ -188,3 +189,17 @@ def test_set_xyunits(quantity_converter):
|
188 | 189 | ax2.yaxis.set_units("inches")
|
189 | 190 | assert ax1.xaxis.get_units() == ax2.xaxis.get_units() == "seconds"
|
190 | 191 | 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