Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e00f69

Browse files
committed
More figure-related doc updates
1 parent 755e05e commit 5e00f69

File tree

1 file changed

+100
-56
lines changed

1 file changed

+100
-56
lines changed

lib/matplotlib/figure.py

Lines changed: 100 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def _stale_figure_callback(self, val):
6262

6363
class AxesStack(Stack):
6464
"""
65-
Specialization of the Stack to handle all tracking of Axes in a Figure.
66-
This stack stores ``key, (ind, axes)`` pairs, where:
65+
Specialization of the `.Stack` to handle all tracking of `.Axes` in a
66+
`.Figure`. This stack stores ``key, (ind, axes)`` pairs, where:
6767
6868
* **key** should be a hash of the args and kwargs
6969
used in generating the Axes.
@@ -81,7 +81,7 @@ def __init__(self):
8181

8282
def as_list(self):
8383
"""
84-
Return a list of the Axes instances that have been added to the figure
84+
Return a list of the Axes instances that have been added to the figure.
8585
"""
8686
ia_list = [a for k, a in self._elements]
8787
ia_list.sort()
@@ -90,7 +90,7 @@ def as_list(self):
9090
def get(self, key):
9191
"""
9292
Return the Axes instance that was added with *key*.
93-
If it is not present, return None.
93+
If it is not present, return *None*.
9494
"""
9595
item = dict(self._elements).get(key)
9696
if item is None:
@@ -694,31 +694,55 @@ def suptitle(self, t, **kwargs):
694694
"""
695695
Add a centered title to the figure.
696696
697-
kwargs are :class:`matplotlib.text.Text` properties. Using figure
698-
coordinates, the defaults are:
697+
Parameters
698+
----------
699+
t : str
700+
The title text.
701+
702+
x : float, default 0.5
703+
The x location of the text in figure coordinates.
704+
705+
y : float, default 0.98
706+
The y location of the text in figure coordinates.
707+
708+
horizontalalignment, ha : {'center', 'left', right'}, default: 'center'
709+
The horizontal alignment of the text.
699710
700-
x : 0.5
701-
The x location of the text in figure coords
711+
verticalalignment, va : {'top', 'center', 'bottom', 'baseline'}, \
712+
default: 'top'
713+
The vertical alignment of the text.
702714
703-
y : 0.98
704-
The y location of the text in figure coords
715+
fontsize, size : default: :rc:`figure.titlesize`
716+
The font size of the text. See `.Text.set_size` for possible
717+
values.
705718
706-
horizontalalignment : 'center'
707-
The horizontal alignment of the text
719+
fontweight, weight : default: :rc:`figuretitleweight`
720+
The font weight of the text. See `.Text.set_weight` for possible
721+
values.
708722
709-
verticalalignment : 'top'
710-
The vertical alignment of the text
711723
712-
If the `fontproperties` keyword argument is given then the
713-
rcParams defaults for `fontsize` (`figure.titlesize`) and
714-
`fontweight` (`figure.titleweight`) will be ignored in favour
715-
of the `FontProperties` defaults.
724+
Returns
725+
-------
726+
text
727+
The `.Text` instance of the title.
716728
717-
A :class:`matplotlib.text.Text` instance is returned.
718729
719-
Example::
730+
Other Parameters
731+
----------------
732+
fontproperties : None or dict, optional
733+
A dict of font properties. If *fontproperties* is given the
734+
default values for font size and weight are taken from the
735+
`FontProperties` defaults. :rc:`figure.titlesize` and
736+
:rc:`figure.titleweight` are ignored in this case.
720737
721-
fig.suptitle('this is the figure title', fontsize=12)
738+
**kwargs
739+
Additional kwargs are :class:`matplotlib.text.Text` properties.
740+
741+
742+
Examples
743+
--------
744+
745+
>>> fig.suptitle('This is the figure title', fontsize=12)
722746
"""
723747
x = kwargs.pop('x', 0.5)
724748
y = kwargs.pop('y', 0.98)
@@ -876,9 +900,9 @@ def figimage(self, X, xo=0, yo=0, alpha=None, norm=None, cmap=None,
876900
return im
877901

878902
def set_size_inches(self, w, h=None, forward=True):
879-
"""Set the figure size in inches (1in == 2.54cm)
903+
"""Set the figure size in inches.
880904
881-
Usage ::
905+
Call signatures::
882906
883907
fig.set_size_inches(w, h) # OR
884908
fig.set_size_inches((w, h))
@@ -887,7 +911,7 @@ def set_size_inches(self, w, h=None, forward=True):
887911
automatically updated; e.g., you can resize the figure window
888912
from the shell
889913
890-
ACCEPTS: a w, h tuple with w, h in inches
914+
ACCEPTS: a (w, h) tuple with w, h in inches
891915
892916
See Also
893917
--------
@@ -972,9 +996,9 @@ def set_facecolor(self, color):
972996

973997
def set_dpi(self, val):
974998
"""
975-
Set the dots-per-inch of the figure.
999+
Set the resolution of the figure in dots-per-inch.
9761000
977-
ACCEPTS: float
1001+
.. ACCEPTS: float
9781002
"""
9791003
self.dpi = val
9801004
self.stale = True
@@ -983,21 +1007,21 @@ def set_figwidth(self, val, forward=True):
9831007
"""
9841008
Set the width of the figure in inches.
9851009
986-
ACCEPTS: float
1010+
.. ACCEPTS: float
9871011
"""
9881012
self.set_size_inches(val, self.get_figheight(), forward=forward)
9891013

9901014
def set_figheight(self, val, forward=True):
9911015
"""
9921016
Set the height of the figure in inches.
9931017
994-
ACCEPTS: float
1018+
.. ACCEPTS: float
9951019
"""
9961020
self.set_size_inches(self.get_figwidth(), val, forward=forward)
9971021

9981022
def set_frameon(self, b):
9991023
"""
1000-
Set whether the figure frame (background) is displayed or invisible
1024+
Set whether the figure frame (background) is displayed or invisible.
10011025
10021026
ACCEPTS: boolean
10031027
"""
@@ -2093,7 +2117,7 @@ def subplots_adjust(self, *args, **kwargs):
20932117
Call signature::
20942118
20952119
subplots_adjust(left=None, bottom=None, right=None, top=None,
2096-
wspace=None, hspace=None)
2120+
wspace=None, hspace=None)
20972121
20982122
Update the :class:`SubplotParams` with *kwargs* (defaulting to rc when
20992123
*None*) and update the subplot locations.
@@ -2194,8 +2218,8 @@ def get_tightbbox(self, renderer):
21942218
"""
21952219
Return a (tight) bounding box of the figure in inches.
21962220
2197-
It only accounts axes title, axis labels, and axis
2198-
ticklabels. Needs improvement.
2221+
Currently, this takes only axes title, axis labels, and axis
2222+
ticklabels into account. Needs improvement.
21992223
"""
22002224

22012225
bb = []
@@ -2447,30 +2471,50 @@ def align_labels(self, axs=None):
24472471

24482472
def figaspect(arg):
24492473
"""
2450-
Create a figure with specified aspect ratio. If *arg* is a number,
2451-
use that aspect ratio. If *arg* is an array, figaspect will
2452-
determine the width and height for a figure that would fit array
2453-
preserving aspect ratio. The figure width, height in inches are
2454-
returned. Be sure to create an axes with equal with and height,
2455-
e.g.,
2456-
2457-
Example usage::
2458-
2459-
# make a figure twice as tall as it is wide
2460-
w, h = figaspect(2.)
2461-
fig = Figure(figsize=(w,h))
2462-
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
2463-
ax.imshow(A, **kwargs)
2464-
2465-
2466-
# make a figure with the proper aspect for an array
2467-
A = rand(5,3)
2468-
w, h = figaspect(A)
2469-
fig = Figure(figsize=(w,h))
2470-
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
2471-
ax.imshow(A, **kwargs)
2472-
2473-
Thanks to Fernando Perez for this function
2474+
Calculate the width and height for a figure with a specified aspect ratio.
2475+
2476+
While the height is taken from :rc:`figure.figsize`, the width is
2477+
adjusted to match the desired aspect ratio. Additionally, it is ensured
2478+
that the width is in the range [4., 16.] and the height is in the range
2479+
[2., 16.]. If necessary, the default height is adjusted to ensure this.
2480+
2481+
Parameters
2482+
----------
2483+
arg : scalar or 2d array
2484+
If a scalar, this defines the aspect ratio (i.e. the ratio height /
2485+
width).
2486+
In case of an array the aspect ratio is number of rows / number of
2487+
columns, so that the array could be fitted in the figure undistorted.
2488+
2489+
Returns
2490+
-------
2491+
width, height
2492+
The figure size in inches.
2493+
2494+
Notes
2495+
-----
2496+
If you want to create an axes within the figure, that still presevers the
2497+
aspect ratio, be sure to create it with equal width and height. See
2498+
examples below.
2499+
2500+
Thanks to Fernando Perez for this function.
2501+
2502+
Examples
2503+
--------
2504+
Make a figure twice as tall as it is wide::
2505+
2506+
w, h = figaspect(2.)
2507+
fig = Figure(figsize=(w, h))
2508+
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
2509+
ax.imshow(A, **kwargs)
2510+
2511+
Make a figure with the proper aspect for an array::
2512+
2513+
A = rand(5,3)
2514+
w, h = figaspect(A)
2515+
fig = Figure(figsize=(w, h))
2516+
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
2517+
ax.imshow(A, **kwargs)
24742518
"""
24752519

24762520
isarray = hasattr(arg, 'shape') and not np.isscalar(arg)

0 commit comments

Comments
 (0)