8000 Test shared axes removal w/ units · matplotlib/matplotlib@4a3c549 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a3c549

Browse files
committed
Test shared axes removal w/ units
1 parent 63ff403 commit 4a3c549

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/matplotlib/tests/test_figure.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from datetime import datetime
12
from pathlib import Path
23
import platform
34

45
from matplotlib import rcParams
56
from matplotlib.testing.decorators import image_comparison, check_figures_equal
67
from matplotlib.axes import Axes
7-
from matplotlib.ticker import AutoMinorLocator, FixedFormatter
8+
from matplotlib.ticker import AutoMinorLocator, FixedFormatter, ScalarFormatter
89
import matplotlib.pyplot as plt
910
import matplotlib.dates as mdates
1011
import matplotlib.gridspec as gridspec
@@ -461,3 +462,21 @@ def test_tightbbox():
461462
# test bbox_extra_artists method...
462463
assert abs(ax.get_tightbbox(renderer, bbox_extra_artists=[]).x1
463464
- 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

Comments
 (0)
0