Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6fc9624

Browse files
authored
Merge pull request#26634 from timhoffm/move-subplotparams
[MNT] Move SubplotParams from figure to gridspec
2 parents469b96b +219323a commit6fc9624

File tree

7 files changed

+102
-99
lines changed

7 files changed

+102
-99
lines changed

‎doc/api/gridspec_api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ Classes
1919
SubplotSpec
2020
GridSpecBase
2121
GridSpecFromSubplotSpec
22+
SubplotParams
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``SubplotParams`` has been moved from ``matplotlib.figure`` to ``matplotlib.gridspec``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
It is still importable from ``matplotlib.figure``, so does not require any changes to
5+
existing code.

‎galleries/examples/subplots_axes_and_figures/auto_subplots_adjust.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ def on_draw(event):
8383
# - `matplotlib.transforms.BboxBase.union`
8484
# - `matplotlib.transforms.Transform.inverted`
8585
# - `matplotlib.figure.Figure.subplots_adjust`
86-
# - `matplotlib.figure.SubplotParams`
86+
# - `matplotlib.gridspec.SubplotParams`
8787
# - `matplotlib.backend_bases.FigureCanvasBase.mpl_connect`

‎lib/matplotlib/figure.py

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
`SubFigure`) with `Figure.add_subfigure` or `Figure.subfigures` methods
1111
(provisional API v3.4).
1212
13-
`SubplotParams`
14-
Control the default spacing between subplots.
15-
1613
Figures are typically created using pyplot methods `~.pyplot.figure`,
1714
`~.pyplot.subplots`, and `~.pyplot.subplot_mosaic`.
1815
@@ -51,7 +48,7 @@
5148
importmatplotlib.imageasmimage
5249

5350
frommatplotlib.axesimportAxes
54-
frommatplotlib.gridspecimportGridSpec
51+
frommatplotlib.gridspecimportGridSpec,SubplotParams
5552
frommatplotlib.layout_engineimport (
5653
ConstrainedLayoutEngine,TightLayoutEngine,LayoutEngine,
5754
PlaceHolderLayoutEngine
@@ -118,66 +115,6 @@ def __setstate__(self, state):
118115
self._counter=itertools.count(next_counter)
119116

120117

121-
classSubplotParams:
122-
"""
123-
A class to hold the parameters for a subplot.
124-
"""
125-
126-
def__init__(self,left=None,bottom=None,right=None,top=None,
127-
wspace=None,hspace=None):
128-
"""
129-
Defaults are given by :rc:`figure.subplot.[name]`.
130-
131-
Parameters
132-
----------
133-
left : float
134-
The position of the left edge of the subplots,
135-
as a fraction of the figure width.
136-
right : float
137-
The position of the right edge of the subplots,
138-
as a fraction of the figure width.
139-
bottom : float
140-
The position of the bottom edge of the subplots,
141-
as a fraction of the figure height.
142-
top : float
143-
The position of the top edge of the subplots,
144-
as a fraction of the figure height.
145-
wspace : float
146-
The width of the padding between subplots,
147-
as a fraction of the average Axes width.
148-
hspace : float
149-
The height of the padding between subplots,
150-
as a fraction of the average Axes height.
151-
"""
152-
forkeyin ["left","bottom","right","top","wspace","hspace"]:
153-
setattr(self,key,mpl.rcParams[f"figure.subplot.{key}"])
154-
self.update(left,bottom,right,top,wspace,hspace)
155-
156-
defupdate(self,left=None,bottom=None,right=None,top=None,
157-
wspace=None,hspace=None):
158-
"""
159-
Update the dimensions of the passed parameters. *None* means unchanged.
160-
"""
161-
if ((leftifleftisnotNoneelseself.left)
162-
>= (rightifrightisnotNoneelseself.right)):
163-
raiseValueError('left cannot be >= right')
164-
if ((bottomifbottomisnotNoneelseself.bottom)
165-
>= (topiftopisnotNoneelseself.top)):
166-
raiseValueError('bottom cannot be >= top')
167-
ifleftisnotNone:
168-
self.left=left
169-
ifrightisnotNone:
170-
self.right=right
171-
ifbottomisnotNone:
172-
self.bottom=bottom
173-
iftopisnotNone:
174-
self.top=top
175-
ifwspaceisnotNone:
176-
self.wspace=wspace
177-
ifhspaceisnotNone:
178-
self.hspace=hspace
179-
180-
181118
classFigureBase(Artist):
182119
"""
183120
Base class for `.Figure` and `.SubFigure` containing the methods that add
@@ -2435,7 +2372,7 @@ def __init__(self,
24352372
frameon : bool, default: :rc:`figure.frameon`
24362373
If ``False``, suppress drawing the figure background patch.
24372374
2438-
subplotpars : `SubplotParams`
2375+
subplotpars : `~matplotlib.gridspec.SubplotParams`
24392376
Subplot parameters. If not given, the default subplot
24402377
parameters :rc:`figure.subplot.*` are used.
24412378

‎lib/matplotlib/figure.pyi

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ from matplotlib.backend_bases import (
1111
frommatplotlib.colorsimportColormap,Normalize
1212
frommatplotlib.colorbarimportColorbar
1313
frommatplotlib.cmimportScalarMappable
14-
frommatplotlib.gridspecimportGridSpec,SubplotSpec
14+
frommatplotlib.gridspecimportGridSpec,SubplotSpec,SubplotParamsasSubplotParams
1515
frommatplotlib.imageimport_ImageBase,FigureImage
1616
frommatplotlib.layout_engineimportLayoutEngine
1717
frommatplotlib.legendimportLegend
@@ -27,32 +27,6 @@ from collections.abc import Callable, Iterable
2727
fromtypingimportAny,IO,Literal,overload
2828
from .typingimportColorType,HashableList
2929

30-
classSubplotParams:
31-
def__init__(
32-
self,
33-
left:float|None= ...,
34-
bottom:float|None= ...,
35-
right:float|None= ...,
36-
top:float|None= ...,
37-
wspace:float|None= ...,
38-
hspace:float|None= ...,
39-
)->None: ...
40-
left:float
41-
right:float
42-
bottom:float
43-
top:float
44-
wspace:float
45-
hspace:float
46-
defupdate(
47-
self,
48-
left:float|None= ...,
49-
bottom:float|None= ...,
50-
right:float|None= ...,
51-
top:float|None= ...,
52-
wspace:float|None= ...,
53-
hspace:float|None= ...,
54-
)->None: ...
55-
5630
classFigureBase(Artist):
5731
artists:list[Artist]
5832
lines:list[Line2D]

‎lib/matplotlib/gridspec.py

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class GridSpec(GridSpecBase):
320320
A grid layout to place subplots within a figure.
321321
322322
The location of the grid cells is determined in a similar way to
323-
`~.figure.SubplotParams` using *left*, *right*, *top*, *bottom*, *wspace*
323+
`.SubplotParams` using *left*, *right*, *top*, *bottom*, *wspace*
324324
and *hspace*.
325325
326326
Indexing a GridSpec instance returns a `.SubplotSpec`.
@@ -424,7 +424,7 @@ def get_subplot_params(self, figure=None):
424424
iffigureisNone:
425425
kw= {k:mpl.rcParams["figure.subplot."+k]
426426
forkinself._AllowedKeys}
427-
subplotpars=mpl.figure.SubplotParams(**kw)
427+
subplotpars=SubplotParams(**kw)
428428
else:
429429
subplotpars=copy.copy(figure.subplotpars)
430430

@@ -517,9 +517,9 @@ def get_subplot_params(self, figure=None):
517517
figbox=self._subplot_spec.get_position(figure)
518518
left,bottom,right,top=figbox.extents
519519

520-
returnmpl.figure.SubplotParams(left=left,right=right,
521-
bottom=bottom,top=top,
522-
wspace=wspace,hspace=hspace)
520+
returnSubplotParams(left=left,right=right,
521+
bottom=bottom,top=top,
522+
wspace=wspace,hspace=hspace)
523523

524524
defget_topmost_subplotspec(self):
525525
"""
@@ -736,3 +736,63 @@ def subgridspec(self, nrows, ncols, **kwargs):
736736
fig.add_subplot(gssub[0, i])
737737
"""
738738
returnGridSpecFromSubplotSpec(nrows,ncols,self,**kwargs)
739+
740+
741+
classSubplotParams:
742+
"""
743+
Parameters defining the positioning of a subplots grid in a figure.
744+
"""
745+
746+
def__init__(self,left=None,bottom=None,right=None,top=None,
747+
wspace=None,hspace=None):
748+
"""
749+
Defaults are given by :rc:`figure.subplot.[name]`.
750+
751+
Parameters
752+
----------
753+
left : float
754+
The position of the left edge of the subplots,
755+
as a fraction of the figure width.
756+
right : float
757+
The position of the right edge of the subplots,
758+
as a fraction of the figure width.
759+
bottom : float
760+
The position of the bottom edge of the subplots,
761+
as a fraction of the figure height.
762+
top : float
763+
The position of the top edge of the subplots,
764+
as a fraction of the figure height.
765+
wspace : float
766+
The width of the padding between subplots,
767+
as a fraction of the average Axes width.
768+
hspace : float
769+
The height of the padding between subplots,
770+
as a fraction of the average Axes height.
771+
"""
772+
forkeyin ["left","bottom","right","top","wspace","hspace"]:
773+
setattr(self,key,mpl.rcParams[f"figure.subplot.{key}"])
774+
self.update(left,bottom,right,top,wspace,hspace)
775+
776+
defupdate(self,left=None,bottom=None,right=None,top=None,
777+
wspace=None,hspace=None):
778+
"""
779+
Update the dimensions of the passed parameters. *None* means unchanged.
780+
"""
781+
if ((leftifleftisnotNoneelseself.left)
782+
>= (rightifrightisnotNoneelseself.right)):
783+
raiseValueError('left cannot be >= right')
784+
if ((bottomifbottomisnotNoneelseself.bottom)
785+
>= (topiftopisnotNoneelseself.top)):
786+
raiseValueError('bottom cannot be >= top')
787+
ifleftisnotNone:
788+
self.left=left
789+
ifrightisnotNone:
790+
self.right=right
791+
ifbottomisnotNone:
792+
self.bottom=bottom
793+
iftopisnotNone:
794+
self.top=top
795+
ifwspaceisnotNone:
796+
self.wspace=wspace
797+
ifhspaceisnotNone:
798+
self.hspace=hspace

‎lib/matplotlib/gridspec.pyi

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import numpy as np
55

66
frommatplotlib.axesimportAxes,SubplotBase
77
frommatplotlib.backend_basesimportRendererBase
8-
frommatplotlib.figureimportFigure,SubplotParams
8+
frommatplotlib.figureimportFigure
99
frommatplotlib.transformsimportBbox
1010

1111
classGridSpecBase:
@@ -132,3 +132,29 @@ class SubplotSpec:
132132
defsubgridspec(
133133
self,nrows:int,ncols:int,**kwargs
134134
)->GridSpecFromSubplotSpec: ...
135+
136+
classSubplotParams:
137+
def__init__(
138+
self,
139+
left:float|None= ...,
140+
bottom:float|None= ...,
141+
right:float|None= ...,
142+
top:float|None= ...,
143+
wspace:float|None= ...,
144+
hspace:float|None= ...,
145+
)->None: ...
146+
left:float
147+
right:float
148+
bottom:float
149+
top:float
150+
wspace:float
151+
hspace:float
152+
defupdate(
153+
self,
154+
left:float|None= ...,
155+
bottom:float|None= ...,
156+
right:float|None= ...,
157+
top:float|None= ...,
158+
wspace:float|None= ...,
159+
hspace:float|None= ...,
160+
)->None: ...

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp