@@ -62,8 +62,8 @@ def _stale_figure_callback(self, val):
62
62
63
63
class AxesStack (Stack ):
64
64
"""
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:
67
67
68
68
* **key** should be a hash of the args and kwargs
69
69
used in generating the Axes.
@@ -81,7 +81,7 @@ def __init__(self):
81
81
82
82
def as_list (self ):
83
83
"""
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.
85
85
"""
86
86
ia_list = [a for k , a in self ._elements ]
87
87
ia_list .sort ()
@@ -90,7 +90,7 @@ def as_list(self):
90
90
def get (self , key ):
91
91
"""
92
92
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* .
94
94
"""
95
95
item = dict (self ._elements ).get (key )
96
96
if item is None :
@@ -692,31 +692,55 @@ def suptitle(self, t, **kwargs):
692
692
"""
693
693
Add a centered title to the figure.
694
694
695
- kwargs are :class:`matplotlib.text.Text` properties. Using figure
696
- coordinates, the defaults are:
695
+ Parameters
696
+ ----------
697
+ t : str
698
+ The title text.
699
+
700
+ x : float, default 0.5
701
+ The x location of the text in figure coordinates.
702
+
703
+ y : float, default 0.98
704
+ The y location of the text in figure coordinates.
705
+
706
+ horizontalalignment, ha : {'center', 'left', right'}, default: 'center'
707
+ The horizontal alignment of the text.
697
708
698
- x : 0.5
699
- The x location of the text in figure coords
709
+ verticalalignment, va : {'top', 'center', 'bottom', 'baseline'}, \
710
+ default: 'top'
711
+ The vertical alignment of the text.
700
712
701
- y : 0.98
702
- The y location of the text in figure coords
713
+ fontsize, size : default: :rc:`figure.titlesize`
714
+ The font size of the text. See `.Text.set_size` for possible
715
+ values.
716
+
717
+ fontweight, weight : default: :rc:`figuretitleweight`
718
+ The font weight of the text. See `.Text.set_weight` for possible
719
+ values.
720
+
721
+
722
+ Returns
723
+ -------
724
+ text
725
+ The `.Text` instance of the title.
703
726
704
- horizontalalignment : 'center'
705
- The horizontal alignment of the text
706
727
707
- verticalalignment : 'top'
708
- The vertical alignment of the text
728
+ Other Parameters
729
+ ----------------
730
+ fontproperties : None or dict, optional
731
+ A dict of font properties. If *fontproperties* is given the
732
+ default values for font size and weight are taken from the
733
+ `FontProperties` defaults. :rc:`figure.titlesize` and
734
+ :rc:`figure.titleweight` are ignored in this case.
709
735
710
- If the `fontproperties` keyword argument is given then the
711
- rcParams defaults for `fontsize` (`figure.titlesize`) and
712
- `fontweight` (`figure.titleweight`) will be ignored in favour
713
- of the `FontProperties` defaults.
736
+ **kwargs
737
+ Additional kwargs are :class:`matplotlib.text.Text` properties.
714
738
715
- A :class:`matplotlib.text.Text` instance is returned.
716
739
717
- Example::
740
+ Examples
741
+ --------
718
742
719
- fig.suptitle('this is the figure title', fontsize=12)
743
+ >>> fig.suptitle('This is the figure title', fontsize=12)
720
744
"""
721
745
x = kwargs .pop ('x' , 0.5 )
722
746
y = kwargs .pop ('y' , 0.98 )
@@ -871,9 +895,9 @@ def figimage(self, X,
871
895
return im
872
896
873
897
def set_size_inches (self , w , h = None , forward = True ):
874
- """Set the figure size in inches (1in == 2.54cm)
898
+ """Set the figure size in inches.
875
899
876
- Usage ::
900
+ Call signatures ::
877
901
878
902
fig.set_size_inches(w, h) # OR
879
903
fig.set_size_inches((w, h))
@@ -882,7 +906,7 @@ def set_size_inches(self, w, h=None, forward=True):
882
906
automatically updated; e.g., you can resize the figure window
883
907
from the shell
884
908
885
- ACCEPTS: a w, h tuple with w, h in inches
909
+ ACCEPTS: a ( w, h) tuple with w, h in inches
886
910
887
911
See Also
888
912
--------
@@ -968,9 +992,9 @@ def set_facecolor(self, color):
968
992
969
993
def set_dpi (self , val ):
970
994
"""
971
- Set the dots-per-inch of the figure
995
+ Set the resolution of the figure in dots-per-inch.
972
996
973
- ACCEPTS: float
997
+ .. ACCEPTS: float
974
998
"""
975
999
self .dpi = val
976
1000
self .stale = True
@@ -979,21 +1003,21 @@ def set_figwidth(self, val, forward=True):
979
1003
"""
980
1004
Set the width of the figure in inches
981
1005
982
- ACCEPTS: float
1006
+ .. ACCEPTS: float
983
1007
"""
984
1008
self .set_size_inches (val , self .get_figheight (), forward = forward )
985
1009
986
1010
def set_figheight (self , val , forward = True ):
987
1011
"""
988
1012
Set the height of the figure in inches
989
1013
990
- ACCEPTS: float
1014
+ .. ACCEPTS: float
991
1015
"""
992
1016
self .set_size_inches (self .get_figwidth (), val , forward = forward )
993
1017
994
1018
def set_frameon (self , b ):
995
1019
"""
996
- Set whether the figure frame (background) is displayed or invisible
1020
+ Set whether the figure frame (background) is displayed or invisible.
997
1021
998
1022
ACCEPTS: boolean
999
1023
"""
@@ -2079,7 +2103,7 @@ def subplots_adjust(self, *args, **kwargs):
2079
2103
Call signature::
2080
2104
2081
2105
subplots_adjust(left=None, bottom=None, right=None, top=None,
2082
- wspace=None, hspace=None)
2106
+ wspace=None, hspace=None)
2083
2107
2084
2108
Update the :class:`SubplotParams` with *kwargs* (defaulting to rc when
2085
2109
*None*) and update the subplot locations.
@@ -2180,8 +2204,8 @@ def get_tightbbox(self, renderer):
2180
2204
"""
2181
2205
Return a (tight) bounding box of the figure in inches.
2182
2206
2183
- It only accounts axes title, axis labels, and axis
2184
- ticklabels. Needs improvement.
2207
+ Currently, this takes only axes title, axis labels, and axis
2208
+ ticklabels into account . Needs improvement.
2185
2209
"""
2186
2210
2187
2211
bb = []
@@ -2437,30 +2461,50 @@ def align_labels(self, axs=None):
2437
2461
2438
2462
def figaspect (arg ):
2439
2463
"""
2440
- Create a figure with specified aspect ratio. If *arg* is a number,
2441
- use that aspect ratio. If *arg* is an array, figaspect will
2442
- determine the width and height for a figure that would fit array
2443
- preserving aspect ratio. The figure width, height in inches are
2444
- returned. Be sure to create an axes with equal with and height,
2445
- e.g.,
2446
-
2447
- Example usage::
2448
-
2449
- # make a figure twice as tall as it is wide
2450
- w, h = figaspect(2.)
2451
- fig = Figure(figsize=(w,h))
2452
- ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
2453
- ax.imshow(A, **kwargs)
2454
-
2455
-
2456
- # make a figure with the proper aspect for an array
2457
- A = rand(5,3)
2458
- w, h = figaspect(A)
2459
- fig = Figure(figsize=(w,h))
2460
- ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
2461
- ax.imshow(A, **kwargs)
2462
-
2463
- Thanks to Fernando Perez for this function
2464
+ Calculate the width and height for a figure with a specified aspect ratio.
2465
+
2466
+ While the height is taken from :rc:`figure.figsize`, the width is
2467
+ adjusted to match the desired aspect ratio. Additionally, it is ensured
2468
+ that the width is in the range [4., 16.] and the height is in the range
2469
+ [2., 16.]. If necessary, the default height is adjusted to ensure this.
2470
+
2471
+ Parameters
2472
+ ----------
2473
+ arg : scalar or 2d array
2474
+ If a scalar, this defines the aspect ratio (i.e. the ratio height /
2475
+ width).
2476
+ In case of an array the aspect ratio is number of rows / number of
2477
+ columns, so that the array could be fitted in the figure undistorted.
2478
+
2479
+ Returns
2480
+ -------
2481
+ width, height
2482
+ The figure size in inches.
2483
+
2484
+ Notes
2485
+ -----
2486
+ If you want to create an axes within the figure, that still presevers the
2487
+ aspect ratio, be sure to create it with equal width and height. See
2488
+ examples below.
2489
+
2490
+ Thanks to Fernando Perez for this function.
2491
+
2492
+ Examples
2493
+ --------
2494
+ Make a figure twice as tall as it is wide::
2495
+
2496
+ w, h = figaspect(2.)
2497
+ fig = Figure(figsize=(w, h))
2498
+ ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
2499
+ ax.imshow(A, **kwargs)
2500
+
2501
+ Make a figure with the proper aspect for an array::
2502
+
2503
+ A = rand(5,3)
2504
+ w, h = figaspect(A)
2505
+ fig = Figure(figsize=(w, h))
2506
+ ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
2507
+ ax.imshow(A, **kwargs)
2464
2508
"""
2465
2509
2466
2510
isarray = hasattr (arg , 'shape' ) and not np .isscalar (arg )
0 commit comments