Skip to content

Commit 76899f3

Browse files
committed
Store figsize in _figure_spec object
Fixes #2891
1 parent 1524d43 commit 76899f3

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

seaborn/_core/plot.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ class Plot:
149149
_limits: dict[str, tuple[Any, Any]]
150150
_labels: dict[str, str | Callable[[str], str] | None]
151151

152-
_subplot_spec: dict[str, Any] # TODO values type
153152
_facet_spec: FacetSpec
154153
_pair_spec: PairSpec
155154

155+
_figure_spec: dict[str, Any]
156+
_subplot_spec: dict[str, Any]
157+
156158
def __init__(
157159
self,
158160
*args: DataSource | VariableSpec,
@@ -175,10 +177,12 @@ def __init__(
175177
self._limits = {}
176178
self._labels = {}
177179

178-
self._subplot_spec = {}
179180
self._facet_spec = {}
180181
self._pair_spec = {}
181182

183+
self._subplot_spec = {}
184+
self._figure_spec = {}
185+
182186
self._target = None
183187

184188
def _resolve_positionals(
@@ -242,10 +246,12 @@ def _clone(self) -> Plot:
242246
new._labels.update(self._labels)
243247
new._limits.update(self._limits)
244248

245-
new._subplot_spec.update(self._subplot_spec)
246249
new._facet_spec.update(self._facet_spec)
247250
new._pair_spec.update(self._pair_spec)
248251

252+
new._figure_spec.update(self._figure_spec)
253+
new._subplot_spec.update(self._subplot_spec)
254+
249255
new._target = self._target
250256

251257
return new
@@ -612,8 +618,7 @@ def configure(
612618

613619
new = self._clone()
614620

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

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

827832
# --- Figure initialization
828-
figure_kws = {"figsize": getattr(p, "_figsize", None)} # TODO fix
829833
self._figure = subplots.init_figure(
830-
pair_spec, self.pyplot, figure_kws, p._target,
834+
pair_spec, self.pyplot, p._figure_spec, p._target,
831835
)
832836

833837
# --- Figure annotation

tests/_core/test_plot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,12 @@ def test_2d_with_order(self, long_df, reorder):
11221122
p = Plot(long_df).facet(**variables, order=order)
11231123
self.check_facet_results_2d(p, long_df, variables, order)
11241124

1125+
def test_figsize(self):
1126+
1127+
figsize = (4, 2)
1128+
p = Plot().configure(figsize=figsize).plot()
1129+
assert tuple(p._figure.get_size_inches()) == figsize
1130+
11251131
def test_axis_sharing(self, long_df):
11261132

11271133
variables = {"row": "a", "col": "c"}

0 commit comments

Comments
 (0)