Test if setting the locator only will update the AutoDateFormatter to use the new locator.
()
| 296 | |
| 297 | |
| 298 | def test_locator_set_formatter(): |
| 299 | """ |
| 300 | Test if setting the locator only will update the AutoDateFormatter to use |
| 301 | the new locator. |
| 302 | """ |
| 303 | plt.rcParams["date.autoformatter.minute"] = "%d %H:%M" |
| 304 | t = [datetime.datetime(2018, 9, 30, 8, 0), |
| 305 | datetime.datetime(2018, 9, 30, 8, 59), |
| 306 | datetime.datetime(2018, 9, 30, 10, 30)] |
| 307 | x = [2, 3, 1] |
| 308 | |
| 309 | fig, ax = plt.subplots() |
| 310 | ax.plot(t, x) |
| 311 | ax.xaxis.set_major_locator(mdates.MinuteLocator((0, 30))) |
| 312 | fig.canvas.draw() |
| 313 | ticklabels = [tl.get_text() for tl in ax.get_xticklabels()] |
| 314 | expected = ['30 08:00', '30 08:30', '30 09:00', |
| 315 | '30 09:30', '30 10:00', '30 10:30'] |
| 316 | assert ticklabels == expected |
| 317 | |
| 318 | ax.xaxis.set_major_locator(mticker.NullLocator()) |
| 319 | ax.xaxis.set_minor_locator(mdates.MinuteLocator((5, 55))) |
| 320 | decoy_loc = mdates.MinuteLocator((12, 27)) |
| 321 | ax.xaxis.set_minor_formatter(mdates.AutoDateFormatter(decoy_loc)) |
| 322 | |
| 323 | ax.xaxis.set_minor_locator(mdates.MinuteLocator((15, 45))) |
| 324 | fig.canvas.draw() |
| 325 | ticklabels = [tl.get_text() for tl in ax.get_xticklabels(which="minor")] |
| 326 | expected = ['30 08:15', '30 08:45', '30 09:15', '30 09:45', '30 10:15'] |
| 327 | assert ticklabels == expected |
| 328 | |
| 329 | |
| 330 | def test_date_formatter_callable(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…