|
| 1 | +from datetime import datetime |
1 | 2 | from pathlib import Path |
2 | 3 | import platform |
3 | 4 |
|
4 | 5 | from matplotlib import rcParams |
5 | 6 | from matplotlib.testing.decorators import image_comparison, check_figures_equal |
6 | 7 | from matplotlib.axes import Axes |
7 | | -from matplotlib.ticker import AutoMinorLocator, FixedFormatter |
| 8 | +from matplotlib.ticker import AutoMinorLocator, FixedFormatter, ScalarFormatter |
8 | 9 | import matplotlib.pyplot as plt |
9 | 10 | import matplotlib.dates as mdates |
10 | 11 | import matplotlib.gridspec as gridspec |
@@ -461,3 +462,21 @@ def test_tightbbox(): |
461 | 462 | # test bbox_extra_artists method... |
462 | 463 | assert abs(ax.get_tightbbox(renderer, bbox_extra_artists=[]).x1 |
463 | 464 | - x1Nom * fig.dpi) < 2 |
| 465 | + |
| 466 | + |
| 467 | +def test_axes_removal(): |
| 468 | + # Check that units can set the formatter after an Axes removal |
| 469 | + fig, axs = plt.subplots(1, 2, sharex=True) |
| 470 | + axs[1].remove() |
| 471 | + axs[0].plot([datetime(2000, 1, 1), datetime(2000, 2, 1)], [0, 1]) |
| 472 | + assert isinstance(axs[0].xaxis.get_major_formatter(), |
| 473 | + mdates.AutoDateFormatter) |
| 474 | + |
| 475 | + # Check that manually setting the formatter, then removing Axes keeps |
| 476 | + # the set formatter. |
| 477 | + fig, axs = plt.subplots(1, 2, sharex=True) |
| 478 | + axs[1].xaxis.set_major_formatter(ScalarFormatter()) |
| 479 | + axs[1].remove() |
| 480 | + axs[0].plot([datetime(2000, 1, 1), datetime(2000, 2, 1)], [0, 1]) |
| 481 | + assert isinstance(axs[0].xaxis.get_major_formatter(), |
| 482 | + ScalarFormatter) |
0 commit comments