@@ -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 :
@@ -694,31 +694,55 @@ def suptitle(self, t, **kwargs):
694
694
"""
695
695
Add a centered title to the figure.
696
696
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.
699
710
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.
702
714
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.
705
718
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.
708
722
709
- verticalalignment : 'top'
710
- The vertical alignment of the text
711
723
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 .
716
728
717
- A :class:`matplotlib.text.Text` instance is returned.
718
729
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.
720
737
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)
722
746
"""
723
747
x = kwargs .pop ('x' , 0.5 )
724
748
y = kwargs .pop ('y' , 0.98 )
@@ -876,9 +900,9 @@ def figimage(self, X, xo=0, yo=0, alpha=None, norm=None, cmap=None,
876
900
return im
877
901
878
902
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.
880
904
881
- Usage ::
905
+ Call signatures ::
882
906
883
907
fig.set_size_inches(w, h) # OR
884
908
fig.set_size_inches((w, h))
@@ -887,7 +911,7 @@ def set_size_inches(self, w, h=None, forward=True):
887
911
automatically updated; e.g., you can resize the figure window
888
912
from the shell
889
913
890
- ACCEPTS: a w, h tuple with w, h in inches
914
+ ACCEPTS: a ( w, h) tuple with w, h in inches
891
915
892
916
See Also
893
917
--------
@@ -972,9 +996,9 @@ def set_facecolor(self, color):
972
996
973
997
def set_dpi (self , val ):
974
998
"""
975
- Set the dots-per-inch of the figure.
999
+ Set the resolution of the figure in dots-per-inch .
976
1000
977
- ACCEPTS: float
1001
+ .. ACCEPTS: float
978
1002
"""
979
1003
self .dpi = val
980
1004
self .stale = True
@@ -983,21 +1007,21 @@ def set_figwidth(self, val, forward=True):
983
1007
"""
984
1008
Set the width of the figure in inches.
985
1009
986
- ACCEPTS: float
1010
+ .. ACCEPTS: float
987
1011
"""
988
1012
self .set_size_inches (val , self .get_figheight (), forward = forward )
989
1013
990
1014
def set_figheight (self , val , forward = True ):
991
1015
"""
992
1016
Set the height of the figure in inches.
993
1017
994
- ACCEPTS: float
1018
+ .. ACCEPTS: float
995
1019
"""
996
1020
self .set_size_inches (self .get_figwidth (), val , forward = forward )
997
1021
998
1022
def set_frameon (self , b ):
999
1023
"""
1000
- Set whether the figure frame (background) is displayed or invisible
1024
+ Set whether the figure frame (background) is displayed or invisible.
1001
1025
1002
1026
ACCEPTS: boolean
1003
1027
"""
@@ -2093,7 +2117,7 @@ def subplots_adjust(self, *args, **kwargs):
2093
2117
Call signature::
2094
2118
2095
2119
subplots_adjust(left=None, bottom=None, right=None, top=None,
2096
- wspace=None, hspace=None)
2120
+ wspace=None, hspace=None)
2097
2121
2098
2122
Update the :class:`SubplotParams` with *kwargs* (defaulting to rc when
2099
2123
*None*) and update the subplot locations.
@@ -2194,8 +2218,8 @@ def get_tightbbox(self, renderer):
2194
2218
"""
2195
2219
Return a (tight) bounding box of the figure in inches.
2196
2220
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.
2199
2223
"""
2200
2224
2201
2225
bb = []
@@ -2447,30 +2471,50 @@ def align_labels(self, axs=None):
2447
2471
2448
2472
def figaspect (arg ):
2449
2473
"""
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)
2474
2518
"""
2475
2519
2476
2520
isarray = hasattr (arg , 'shape' ) and not np .isscalar (arg )
0 commit comments