Skip to content

Commit

Permalink
Store figsize in _figure_spec object
Browse files Browse the repository at this point in the history
Fixes #2891
  • Loading branch information
mwaskom committed Jul 22, 2022
1 parent 1524d43 commit 76899f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 11 additions & 7 deletions seaborn/_core/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ class Plot:
_limits: dict[str, tuple[Any, Any]]
_labels: dict[str, str | Callable[[str], str] | None]

_subplot_spec: dict[str, Any] # TODO values type
_facet_spec: FacetSpec
_pair_spec: PairSpec

_figure_spec: dict[str, Any]
_subplot_spec: dict[str, Any]

def __init__(
self,
*args: DataSource | VariableSpec,
Expand All @@ -175,10 +177,12 @@ def __init__(
self._limits = {}
self._labels = {}

self._subplot_spec = {}
self._facet_spec = {}
self._pair_spec = {}

self._subplot_spec = {}
self._figure_spec = {}

self._target = None

def _resolve_positionals(
Expand Down Expand Up @@ -242,10 +246,12 @@ def _clone(self) -> Plot:
new._labels.update(self._labels)
new._limits.update(self._limits)

new._subplot_spec.update(self._subplot_spec)
new._facet_spec.update(self._facet_spec)
new._pair_spec.update(self._pair_spec)

new._figure_spec.update(self._figure_spec)
new._subplot_spec.update(self._subplot_spec)

new._target = self._target

return new
Expand Down Expand Up @@ -612,8 +618,7 @@ def configure(

new = self._clone()

# TODO this is a hack; make a proper figure spec object
new._figsize = figsize # type: ignore
new._figure_spec["figsize"] = figsize

if sharex is not None:
new._subplot_spec["sharex"] = sharex
Expand Down Expand Up @@ -825,9 +830,8 @@ def _setup_figure(self, p: Plot, common: PlotData, layers: list[Layer]) -> None:
self._subplots = subplots = Subplots(subplot_spec, facet_spec, pair_spec)

# --- Figure initialization
figure_kws = {"figsize": getattr(p, "_figsize", None)} # TODO fix
self._figure = subplots.init_figure(
pair_spec, self.pyplot, figure_kws, p._target,
pair_spec, self.pyplot, p._figure_spec, p._target,
)

# --- Figure annotation
Expand Down
6 changes: 6 additions & 0 deletions tests/_core/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,12 @@ def test_2d_with_order(self, long_df, reorder):
p = Plot(long_df).facet(**variables, order=order)
self.check_facet_results_2d(p, long_df, variables, order)

def test_figsize(self):

figsize = (4, 2)
p = Plot().configure(figsize=figsize).plot()
assert tuple(p._figure.get_size_inches()) == figsize

def test_axis_sharing(self, long_df):

variables = {"row": "a", "col": "c"}
Expand Down

0 comments on commit 76899f3

Please sign in to comment.