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

Skip to content

Commit 3bc3880

Browse files
committed
more kwarg docs
svn path=/trunk/matplotlib/; revision=2953
1 parent c089615 commit 3bc3880

File tree

9 files changed

+247
-66
lines changed

9 files changed

+247
-66
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2007-01-02 Added additional kwarg documentation - JDH
2+
13
2006-12-28 Improved error message for nonpositive input to log
24
transform; added log kwarg to bar, barh, and hist,
35
and modified bar method to behave sensibly by default

lib/matplotlib/axes.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,41 @@ def __init__(self, fig, rect,
382382
label='',
383383
**kwargs
384384
):
385+
"""
386+
387+
Build an Axes instance in Figure with
388+
rect=[left, bottom, width,height in Figure coords
389+
390+
adjustable: ['box' | 'datalim']
391+
alpha: the alpha transparency
392+
anchor: ['C', 'SW', 'S', 'SE', 'E', 'NE', 'N', 'NW', 'W']
393+
aspect: ['auto' | 'equal' | aspect_ratio]
394+
autoscale_on: boolean - whether or not to autoscale the viewlim
395+
axis_bgcolor: any matplotlib color - see help(colors)
396+
axisbelow: draw the grids and ticks below the other artists
397+
cursor_props: a (float, color) tuple
398+
figure: a Figure instance
399+
frame_on: a boolean - draw the axes frame
400+
label: the axes label
401+
navigate: True|False
402+
navigate_mode: the navigation toolbar button status: 'PAN', 'ZOOM', or None
403+
position: [left, bottom, width,height in Figure coords
404+
sharex : an Axes instance to share the x-axis with
405+
sharey : an Axes instance to share the y-axis with
406+
title: the title string
407+
visible: a boolean - whether the axes is visible
408+
xlabel: the xlabel
409+
xlim: (xmin, xmax) view limits
410+
xscale: ['log' | 'linear' ]
411+
xticklabels: sequence of strings
412+
xticks: sequence of floats
413+
ylabel: the ylabel strings
414+
ylim: (ymin, ymax) view limits
415+
yscale: ['log' | 'linear']
416+
yticklabels: sequence of strings
417+
yticks: sequence of floats
418+
419+
"""
385420
Artist.__init__(self)
386421
self._position = map(makeValue, rect)
387422
self._originalPosition = rect
@@ -4738,6 +4773,9 @@ class Subplot(SubplotBase, Axes):
47384773
Subplot(211) # 2 rows, 1 column, first (upper) plot
47394774
"""
47404775
def __init__(self, fig, *args, **kwargs):
4776+
"""
4777+
See Axes base class documentation for args and kwargs
4778+
"""
47414779
SubplotBase.__init__(self, fig, *args)
47424780
Axes.__init__(self, fig, [self.figLeft, self.figBottom,
47434781
self.figW, self.figH], **kwargs)
@@ -4768,6 +4806,9 @@ class PolarAxes(Axes):
47684806
RESOLUTION = 200
47694807

47704808
def __init__(self, *args, **kwarg):
4809+
"""
4810+
See Axes base class for args and kwargs documentation
4811+
"""
47714812
Axes.__init__(self, *args, **kwarg)
47724813
self.set_aspect('equal', adjustable='box', anchor='C')
47734814
self.cla()
@@ -5120,6 +5161,7 @@ def __init__(self, fig, *args, **kwargs):
51205161
PolarAxes.__init__(self, fig, [self.figLeft, self.figBottom, self.figW, self.figH], **kwargs)
51215162

51225163

5164+
51235165
artist.kwdocd['Axes'] = artist.kwdocd['Subplot'] = '\n'.join(artist.ArtistInspector(Axes).pprint_setters(leadingspace=12))
51245166
"""
51255167
# this is some discarded code I was using to find the minimum positive

lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,9 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
936936
filename - can also be a file object on image backends
937937
orientation - only currently applies to PostScript printing.
938938
dpi - the dots per inch to save the figure in; if None, use savefig.dpi
939+
facecolor - the facecolor of the figure
940+
edgecolor - the edgecolor of the figure
941+
orientation - 'landscape' | 'portrait' (not supported on all backends)
939942
"""
940943
pass
941944

lib/matplotlib/collections.py

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
from matplotlib import rcParams, verbose
1212

1313
import artist
14-
from artist import Artist
14+
from artist import Artist, kwdocd
1515
from backend_bases import GraphicsContextBase
1616
from cbook import is_string_like, iterable
1717
from colors import colorConverter
1818
from cm import ScalarMappable
1919
from numerix import arange, sin, cos, pi, asarray, sqrt, array, newaxis, ones
2020
from transforms import identity_transform
2121

22+
23+
2224
class Collection(Artist):
2325
"""
2426
All properties in a collection must be sequences. The
@@ -51,6 +53,30 @@ def _get_value(self, val):
5153

5254
raise TypeError('val must be a float or nonzero sequence of floats')
5355

56+
57+
# these are not available for the object inspector until after the
58+
# class is build so we define an initial set here for the init
59+
# function and they will be overridden after object defn
60+
kwdocd['PatchCollection'] = """\
61+
Valid PatchCollection kwargs are:
62+
63+
edgecolors=None,
64+
facecolors=None,
65+
linewidths=None,
66+
antialiaseds = None,
67+
offsets = None,
68+
transOffset = identity_transform(),
69+
norm = None, # optional for ScalarMappable
70+
cmap = None, # ditto
71+
72+
offsets and transOffset are used to translate the patch after
73+
rendering (default no offsets)
74+
75+
If any of edgecolors, facecolors, linewidths, antialiaseds are
76+
None, they default to their patch.* rc params setting, in sequence
77+
form.
78+
"""
79+
5480
class PatchCollection(Collection, ScalarMappable):
5581
"""
5682
Base class for filled regions such as PolyCollection etc.
@@ -90,6 +116,11 @@ def __init__(self,
90116
norm = None, # optional for ScalarMappable
91117
cmap = None, # ditto
92118
):
119+
"""
120+
Create a PatchCollection
121+
122+
%(PatchCollection)s
123+
"""
93124
Collection.__init__(self)
94125
ScalarMappable.__init__(self, norm, cmap)
95126

@@ -108,6 +139,7 @@ def __init__(self,
108139
self._antialiaseds = antialiaseds
109140
self._offsets = offsets
110141
self._transOffset = transOffset
142+
__init__.__doc__ = __init__.__doc__%kwdocd
111143

112144
def get_transoffset(self):
113145
if self._transOffset is None:
@@ -242,10 +274,12 @@ def __init__(self, verts, **kwargs):
242274
verts is a sequence of ( verts0, verts1, ...) where verts_i is
243275
a sequence of xy tuples of vertices, or an equivalent
244276
numerix array of shape (nv,2).
245-
See PatchCollection for kwargs.
277+
278+
%(PatchCollection)s
246279
"""
247280
PatchCollection.__init__(self,**kwargs)
248281
self._verts = verts
282+
__init__.__doc__ = __init__.__doc__%kwdocd
249283

250284
def set_verts(self, verts):
251285
'''This allows one to delay initialization of the vertices.'''
@@ -299,11 +333,14 @@ def __init__(self, xranges, yrange, **kwargs):
299333
"""
300334
xranges : sequence of (xmin, xwidth)
301335
yrange : ymin, ywidth
336+
337+
%(PatchCollection)s
302338
"""
303339
ymin, ywidth = yrange
304340
ymax = ymin + ywidth
305341
verts = [ [(xmin, ymin), (xmin, ymax), (xmin+xwidth, ymax), (xmin+xwidth, ymin)] for xmin, xwidth in xranges]
306342
PolyCollection.__init__(self, verts, **kwargs)
343+
__init__.__doc__ = __init__.__doc__%kwdocd
307344

308345
class RegularPolyCollection(PatchCollection):
309346
def __init__(self,
@@ -325,13 +362,7 @@ def __init__(self,
325362
326363
* rotation is the rotation of the polygon in radians
327364
328-
kwargs: See PatchCollection for more details
329-
330-
* offsets are a sequence of x,y tuples that give the centers of
331-
the polygon in data coordinates
332-
333-
* transOffset is the Transformation instance used to
334-
transform the centers onto the canvas.
365+
%(PatchCollection)s
335366
336367
Example: see examples/dynamic_collection.py for complete example
337368
@@ -359,6 +390,7 @@ def __init__(self,
359390
self.numsides = numsides
360391
self.rotation = rotation
361392
self._update_verts()
393+
__init__.__doc__ = __init__.__doc__%kwdocd
362394

363395
def _update_verts(self):
364396
r = 1.0/math.sqrt(math.pi) # unit area
@@ -422,15 +454,10 @@ def __init__(self,
422454
423455
* rotation is the rotation of the polygon in radians
424456
425-
kwargs: See PatchCollection for more details
426-
427-
* offsets are a sequence of x,y tuples that give the centers of
428-
the polygon in data coordinates
429-
430-
* transOffset is the Transformation instance used to
431-
transform the centers onto the canvas.
432-
"""
457+
%(PatchCollection)s
458+
"""
433459
RegularPolyCollection.__init__(self, dpi, numsides, rotation, sizes, **kwargs)
460+
__init__.__doc__ = __init__.__doc__%kwdocd
434461

435462
def _update_verts(self):
436463
scale = 1.0/math.sqrt(math.pi)

lib/matplotlib/figure.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ def add_axes(self, *args, **kwargs):
418418
add_axes(rect, label='axes2')
419419
420420
The Axes instance will be returned
421+
422+
The following kwargs are supported:
423+
%(Axes)s
421424
"""
422425

423426
key = self._make_key(*args, **kwargs)
@@ -447,6 +450,8 @@ def add_axes(self, *args, **kwargs):
447450
self._seen[key] = a
448451
return a
449452

453+
add_axes.__doc__ = add_axes.__doc__%artist.kwdocd
454+
450455
def add_subplot(self, *args, **kwargs):
451456
"""
452457
Add a subplot. Examples
@@ -461,6 +466,9 @@ def add_subplot(self, *args, **kwargs):
461466
462467
If the figure already has a subplot with key *args, *kwargs then it will
463468
simply make that subplot current and return it
469+
470+
The following kwargs are supported:
471+
%(Axes)s
464472
"""
465473

466474
key = self._make_key(*args, **kwargs)
@@ -488,7 +496,8 @@ def add_subplot(self, *args, **kwargs):
488496
self.sca(a)
489497
self._seen[key] = a
490498
return a
491-
499+
add_subplot.__doc__ = add_subplot.__doc__%artist.kwdocd
500+
492501
def clf(self):
493502
"""
494503
Clear the figure
@@ -596,7 +605,19 @@ def legend(self, handles, labels, loc, **kwargs):
596605
(0,0) is the left, bottom of the figure and 1,1 is the right,
597606
top.
598607
599-
The legend instance is returned
608+
The legend instance is returned. The following kwargs are supported:
609+
610+
isaxes=True # whether this is an axes legend
611+
numpoints = 4 # the number of points in the legend line
612+
prop = FontProperties(size='smaller') # the font property
613+
pad = 0.2 # the fractional whitespace inside the legend border
614+
markerscale = 0.6 # the relative size of legend markers vs. original
615+
shadow # if True, draw a shadow behind legend
616+
labelsep = 0.005 # the vertical space between the legend entries
617+
handlelen = 0.05 # the length of the legend lines
618+
handletextsep = 0.02 # the space between the legend line and legend text
619+
axespad = 0.02 # the border between the axes and legend edge
620+
600621
"""
601622

602623

@@ -634,10 +655,14 @@ def _set_artist_props(self, a):
634655
def gca(self, **kwargs):
635656
"""
636657
Return the current axes, creating one if necessary
658+
659+
The following kwargs are supported
660+
%(Axes)s
637661
"""
638662
ax = self._axstack()
639663
if ax is not None: return ax
640664
return self.add_subplot(111, **kwargs)
665+
gca.__doc__ = gca.__doc__%artist.kwdocd
641666

642667
def sca(self, a):
643668
'Set the current axes to be a and return a'

lib/matplotlib/legend.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,3 +581,6 @@ def get_tbounds(text): #get text bounds in axes coords
581581
if self._loc in (CL, CR, C): # center y
582582
oy = (0.5-h/2)-b
583583
self._offset(ox, oy)
584+
585+
586+
#artist.kwdocd['Legend'] = '\n'.join(artist.ArtistInspector(Legend).pprint_setters(leadingspace=12))

lib/matplotlib/lines.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def __init__(self, xdata, ydata,
138138
**kwargs
139139
):
140140
"""
141-
Initialize the line instance
141+
Create a Line2D instance with x and y data in sequences xdata,
142+
ydata
142143
143144
The kwargs are Line2D properties:
144145
alpha: float

0 commit comments

Comments
 (0)