Skip to content

Commit

Permalink
Avoid direct import of SubFigure for mpl compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Waskom committed Aug 31, 2021
1 parent 878c213 commit 0e63174
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions seaborn/_core/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import pandas as pd
import matplotlib as mpl
from matplotlib.axes import Axes
from matplotlib.figure import Figure, SubFigure
import matplotlib.pyplot as plt # TODO defer import into Plot.show()

from seaborn._core.rules import categorical_order, variable_type
Expand All @@ -28,6 +26,8 @@
from typing import Literal, Any
from collections.abc import Callable, Generator, Iterable, Hashable
from pandas import DataFrame, Series, Index
from matplotlib.axes import Axes
from matplotlib.figure import Figure, SubFigure
from matplotlib.scale import ScaleBase
from matplotlib.colors import Normalize
from seaborn._core.mappings import SemanticMapping
Expand Down Expand Up @@ -85,11 +85,15 @@ def on(self, target: Axes | SubFigure | Figure) -> Plot:

accepted_types: tuple # Allow tuple of various length
if hasattr(mpl.figure, "SubFigure"): # Added in mpl 3.4
accepted_types = Axes, SubFigure, Figure
accepted_types_str = f"{Axes}, {SubFigure}, or {Figure}"
accepted_types = (
mpl.axes.Axes, mpl.figure.SubFigure, mpl.figure.Figure
)
accepted_types_str = (
f"{mpl.axes.Axes}, {mpl.figure.SubFigure}, or {mpl.figure.Figure}"
)
else:
accepted_types = Axes, Figure
accepted_types_str = f"{Axes} or {Figure}"
accepted_types = mpl.axes.Axes, mpl.figure.Figure
accepted_types_str = f"{mpl.axes.Axes} or {mpl.figure.Figure}"
if not isinstance(target, accepted_types):
err = (
f"The `Plot.on` target must be an instance of {accepted_types_str}. "
Expand Down

0 comments on commit 0e63174

Please sign in to comment.