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

Commit68beb9a

Browse files
dstansbytimhoffm
authored andcommitted
Merge pull request#10666 from timhoffm/doc-figure-part-2
More figure-related doc updates
1 parent45598c8 commit68beb9a

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
classAxesStack(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
defas_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= [afork,ainself._elements]
8787
ia_list.sort()
@@ -90,7 +90,7 @@ def as_list(self):
9090
defget(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
ifitemisNone:
@@ -692,31 +692,55 @@ def suptitle(self, t, **kwargs):
692692
"""
693693
Add a centered title to the figure.
694694
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.
697708
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.
700712
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.
703726
704-
horizontalalignment : 'center'
705-
The horizontal alignment of the text
706727
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.
709735
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.
714738
715-
A :class:`matplotlib.text.Text` instance is returned.
716739
717-
Example::
740+
Examples
741+
--------
718742
719-
fig.suptitle('this is the figure title', fontsize=12)
743+
>>>fig.suptitle('This is the figure title', fontsize=12)
720744
"""
721745
x=kwargs.pop('x',0.5)
722746
y=kwargs.pop('y',0.98)
@@ -871,9 +895,9 @@ def figimage(self, X,
871895
returnim
872896

873897
defset_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.
875899
876-
Usage::
900+
Call signatures::
877901
878902
fig.set_size_inches(w, h) # OR
879903
fig.set_size_inches((w, h))
@@ -882,7 +906,7 @@ def set_size_inches(self, w, h=None, forward=True):
882906
automatically updated; e.g., you can resize the figure window
883907
from the shell
884908
885-
ACCEPTS: a w, h tuple with w, h in inches
909+
ACCEPTS: a(w, h) tuple with w, h in inches
886910
887911
See Also
888912
--------
@@ -968,9 +992,9 @@ def set_facecolor(self, color):
968992

969993
defset_dpi(self,val):
970994
"""
971-
Set thedots-per-inch of the figure
995+
Set theresolution of the figure in dots-per-inch.
972996
973-
ACCEPTS: float
997+
..ACCEPTS: float
974998
"""
975999
self.dpi=val
9761000
self.stale=True
@@ -979,21 +1003,21 @@ def set_figwidth(self, val, forward=True):
9791003
"""
9801004
Set the width of the figure in inches
9811005
982-
ACCEPTS: float
1006+
..ACCEPTS: float
9831007
"""
9841008
self.set_size_inches(val,self.get_figheight(),forward=forward)
9851009

9861010
defset_figheight(self,val,forward=True):
9871011
"""
9881012
Set the height of the figure in inches
9891013
990-
ACCEPTS: float
1014+
..ACCEPTS: float
9911015
"""
9921016
self.set_size_inches(self.get_figwidth(),val,forward=forward)
9931017

9941018
defset_frameon(self,b):
9951019
"""
996-
Set whether the figure frame (background) is displayed or invisible
1020+
Set whether the figure frame (background) is displayed or invisible.
9971021
9981022
ACCEPTS: boolean
9991023
"""
@@ -2079,7 +2103,7 @@ def subplots_adjust(self, *args, **kwargs):
20792103
Call signature::
20802104
20812105
subplots_adjust(left=None, bottom=None, right=None, top=None,
2082-
wspace=None, hspace=None)
2106+
wspace=None, hspace=None)
20832107
20842108
Update the :class:`SubplotParams` with *kwargs* (defaulting to rc when
20852109
*None*) and update the subplot locations.
@@ -2180,8 +2204,8 @@ def get_tightbbox(self, renderer):
21802204
"""
21812205
Return a (tight) bounding box of the figure in inches.
21822206
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.
21852209
"""
21862210

21872211
bb= []
@@ -2437,30 +2461,50 @@ def align_labels(self, axs=None):
24372461

24382462
deffigaspect(arg):
24392463
"""
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)
24642508
"""
24652509

24662510
isarray=hasattr(arg,'shape')andnotnp.isscalar(arg)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp