@@ -137,106 +137,25 @@ The same can be done using the pgf backend::
137137
138138 from matplotlib.backends.backend_pgf import PdfPages
139139
140- .. _howto-subplots-adjust :
141140
142- Move the edge of an axes to make room for tick labels
143- -----------------------------------------------------
144-
145- For subplots, you can control the default spacing on the left, right,
146- bottom, and top as well as the horizontal and vertical spacing between
147- multiple rows and columns using the
148- :meth: `matplotlib.figure.Figure.subplots_adjust ` method (in pyplot it
149- is :func: `~matplotlib.pyplot.subplots_adjust `). For example, to move
150- the bottom of the subplots up to make room for some rotated x tick
151- labels::
141+ .. _howto-auto-adjust :
152142
153- fig = plt.figure()
154- fig.subplots_adjust(bottom=0.2)
155- ax = fig.add_subplot(111)
143+ Make room for tick labels
144+ -------------------------
156145
157- You can control the defaults for these parameters in your
158- :file: `matplotlibrc ` file; see :doc: `/tutorials/introductory/customizing `. For
159- example, to make the above setting permanent, you would set::
160-
161- figure.subplot.bottom : 0.2 # the bottom of the subplots of the figure
162-
163- The other parameters you can configure are, with their defaults
164-
165- *left * = 0.125
166- the left side of the subplots of the figure
167- *right * = 0.9
168- the right side of the subplots of the figure
169- *bottom * = 0.1
170- the bottom of the subplots of the figure
171- *top * = 0.9
172- the top of the subplots of the figure
173- *wspace * = 0.2
174- the amount of width reserved for space between subplots,
175- expressed as a fraction of the average axis width
176- *hspace * = 0.2
177- the amount of height reserved for space between subplots,
178- expressed as a fraction of the average axis height
179-
180- If you want additional control, you can create an
181- :class: `~matplotlib.axes.Axes ` using the
182- :func: `~matplotlib.pyplot.axes ` command (or equivalently the figure
183- :meth: `~matplotlib.figure.Figure.add_axes ` method), which allows you to
184- specify the location explicitly::
185-
186- ax = fig.add_axes([left, bottom, width, height])
187-
188- where all values are in fractional (0 to 1) coordinates. See
189- :doc: `/gallery/subplots_axes_and_figures/axes_demo ` for an example of
190- placing axes manually.
146+ By default, Matplotlib uses fixed percentage margins around subplots. This can
147+ lead to labels overlapping or being cut off at the figure boundary. There are
148+ multiple ways to fix this:
191149
192- .. _howto-auto-adjust :
150+ - Manually adapt the subplot parameters using `.Figure.subplots_adjust ` /
151+ `.pyplot.subplots_adjust `.
152+ - Use one of the automatic layout mechanisms:
193153
194- Automatically make room for tick labels
195- ---------------------------------------
154+ - constrained layout ( :doc: ` /tutorials/intermediate/constrainedlayout_guide `)
155+ - tight layout ( :doc: ` /tutorials/intermediate/tight_layout_guide `)
196156
197- .. note ::
198- This is now easier to handle than ever before.
199- Calling :func: `~matplotlib.pyplot.tight_layout ` or alternatively using
200- ``constrained_layout=True `` argument in :func: `~matplotlib.pyplot.subplots `
201- can fix many common layout issues. See the
202- :doc: `/tutorials/intermediate/tight_layout_guide ` and
203- :doc: `/tutorials/intermediate/constrainedlayout_guide ` for more details.
204-
205- The information below is kept here in case it is useful for other
206- purposes.
207-
208- In most use cases, it is enough to simply change the subplots adjust
209- parameters as described in :ref: `howto-subplots-adjust `. But in some
210- cases, you don't know ahead of time what your tick labels will be, or
211- how large they will be (data and labels outside your control may be
212- being fed into your graphing application), and you may need to
213- automatically adjust your subplot parameters based on the size of the
214- tick labels. Any :class: `~matplotlib.text.Text ` instance can report
215- its extent in window coordinates (a negative x coordinate is outside
216- the window), but there is a rub.
217-
218- The :class: `~matplotlib.backend_bases.RendererBase ` instance, which is
219- used to calculate the text size, is not known until the figure is
220- drawn (:meth: `~matplotlib.figure.Figure.draw `). After the window is
221- drawn and the text instance knows its renderer, you can call
222- :meth: `~matplotlib.text.Text.get_window_extent `. One way to solve
223- this chicken and egg problem is to wait until the figure is draw by
224- connecting
225- (:meth: `~matplotlib.backend_bases.FigureCanvasBase.mpl_connect `) to the
226- "on_draw" signal (:class: `~matplotlib.backend_bases.DrawEvent `) and
227- get the window extent there, and then do something with it, e.g., move
228- the left of the canvas over; see :ref: `event-handling-tutorial `.
229-
230- Here is an example that gets a bounding box in relative figure coordinates
231- (0..1) of each of the labels and uses it to move the left of the subplots
232- over so that the tick labels fit in the figure:
233-
234- .. figure :: ../gallery/pyplots/images/sphx_glr_auto_subplots_adjust_001.png
235- :target: ../gallery/pyplots/auto_subplots_adjust.html
236- :align: center
237- :scale: 50
238-
239- Auto Subplots Adjust
157+ - Calculate good values from the size of the plot elements yourself
158+ (:doc: `/gallery/pyplots/auto_subplots_adjust `)
240159
241160.. _howto-align-label :
242161
0 commit comments