Menu

[r889]: / trunk / matplotlib / boilerplate.py  Maximize  Restore  History

Download this file

143 lines (127 with data), 3.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# wrap the plot commands defined in axes. The code generated by this
# file is pasted into pylab.py
_fmtplot = """\
# This function was autogenerated by boilerplate.py. Do not edit as
# changes will be lost
def %(func)s(*args, **kwargs):
# allow callers to override the hold state by passing hold=True|False
b = ishold()
h = popd(kwargs, 'hold', None)
if h is not None:
hold(h)
try:
ret = gca().%(func)s(*args, **kwargs)
except ValueError, msg:
msg = raise_msg_to_str(msg)
error_msg(msg)
hold(b)
else:
draw_if_interactive()
%(mappable)s
hold(b)
return ret
%(func)s.__doc__ = Axes.%(func)s.__doc__ + \"\"\"
Addition kwargs: hold = [True|False] overrides default hold state\"\"\"
"""
_fmtmisc = """\
# This function was autogenerated by boilerplate.py. Do not edit as
# changes will be lost
def %(func)s(*args, **kwargs):
try:
ret = gca().%(func)s(*args, **kwargs)
except ValueError, msg:
msg = raise_msg_to_str(msg)
error_msg(msg)
else:
draw_if_interactive()
return ret
%(func)s.__doc__ = Axes.%(func)s.__doc__
"""
# these methods are all simple wrappers of Axes methods by the same
# name.
_plotcommands = (
'axhline',
'axhspan',
'axvline',
'axvspan',
'bar',
'barh',
'cohere',
'contour',
'csd',
'errorbar',
'fill',
'hist',
'hlines',
'imshow',
'loglog',
'pcolor',
'pcolor_classic',
'pie',
'plot',
'plot_date',
'psd',
'scatter',
'scatter_classic',
'semilogx',
'semilogy',
'specgram',
'spy',
'spy2',
'stem',
'vlines',
)
_misccommands = (
'cla',
'grid',
'legend',
'table',
'text',
)
cmappable = {
'contour' : 'if ret[1].mappable is not None: gci._current = ret[1].mappable',
'scatter' : 'gci._current = ret',
'pcolor' : 'gci._current = ret',
'imshow' : 'gci._current = ret',
'spy2' : 'gci._current = ret',
'specgram' : 'gci._current = ret[-1]',
}
for func in _plotcommands:
if cmappable.has_key(func):
mappable = cmappable[func]
else:
mappable = ''
print _fmtplot%locals()
for func in _misccommands:
print _fmtmisc%locals()
# define the colormap functions
_fmtcmap = """\
# This function was autogenerated by boilerplate.py. Do not edit as
# changes will be lost
def %(name)s():
'set the default colormap to %(name)s and apply to current image if any. See help(colormaps) for more information'
rc('image', cmap='%(name)s')
im = gci()
if im is not None:
im.set_cmap(cm.%(name)s)
draw_if_interactive()
"""
cmaps = (
'autumn',
'bone',
'cool',
'copper',
'flag',
'gray' ,
'hot',
'hsv',
'jet' ,
'pink',
'prism',
'spring',
'summer',
'winter',
)
# add all the colormaps (autumn, hsv, ....)
for name in cmaps:
print _fmtcmap%locals()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.