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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
import new_plot
pyPlot = new_plot
from Numeric import *
from numpy.lib.scimath import *
def _intialize():
global _figure; global _active
_figure = [pyPlot.Plot()]
_active = _figure[-1]
_intialize()
def _validate_active():
global _figure; global _active
if _active.valid(): return
try: _figure.remove(_active)
except ValueError: pass
try:
_active = _figure[-1]
_validate_active()
except IndexError: _intialize()
def figure(which_one = None):
global _figure; global _active
if which_one is None:
_figure.append(pyPlot.Plot())
_active = _figure[-1]
else:
try: _figure.index(which_one)
except ValueError: _figure.append(which_one)
_active = which_one
def current():
_validate_active()
return _active
def close(which_one = None):
global _figure; global _active
if which_one is None:
_active.close()
try: _active = _figure[-1]
except IndexError: _intialize()
elif which_one == 'all':
for fig in _figure: fig.close()
_intialize()
else:
try:
_figure.remove(which_one)
which_one.close()
except ValueError:
which_one.close()
if _active == which_one:
try: _active = _figure[-1]
except IndexError: _intialize()
def cmp_imag(x,y):
if x.real == y.real and x.imag == y.imag: return 0
if x.real <= y.real: return -1
if x.real>= y.real: return 1
def zplane(data,title=None, style = 19):
data = asarray(data,Complex)
xmin = floor(min(data.real))
xmax = ceil(max(data.real))
ymin = floor(min(data.imag))
ymax = ceil(max(data.imag))
if(ymax - ymin) == 0:
ymax = xmax
ymin = xmin
if(xmax - xmin) == 0:
xmax = ymax
xmin = ymin
if xmax < 1.: xmax = 1.
if ymax < 1.: ymax = 1.
if xmin > -1.: xmin = -1.
if ymin > -1.: ymin = -1.
t = arange(100)*2*pi/100.-pi
_active.plot(sin(t),cos(t),'notitle w l lt 0')
_active.hold('on')
_active.plot([xmin,xmax],[0.,0.],'notitle w l lt 0')
_active.plot([0.,0.],[ymin,ymax],'notitle w l lt 0')
if title:
_active.plot(data.real,data.imag, 'title "%s"w p pt %d ps 3' % (title,style))
else:
_active.plot(data.real,data.imag, 'notitle w p pt %d ps 3' % (title,style))
rr = array(data).tolist()
rr.sort(cmp_imag)
SMALL = 1e-2
for i in rr:
count = 0
for j in rr:
if abs(i-j) < SMALL: count = count + 1
#print i.real, i.imag, count
if count > 1:
xpos = 1.03 *(( i.real - xmin) / (xmax - xmin))
ypos = 1.03 *((i.imag - ymin) / (ymax - ymin))
_active.text((xpos,ypos),"%d"%count)
_active.xaxis([xmin,xmax])
_active.yaxis([ymin,ymax])
_active._send('set size ratio %f' % ((ymax-ymin)/(xmax-xmin)))
_active.hold('off')
_active.grid('off')
def plot(*data):
_validate_active()
apply(_active.plot,data)
def polar(*data):
_validate_active()
apply(_active.polar,data)
def autoscale():
_validate_active()
_active.autoscale()
def logx(st='on'):
_validate_active()
_active.logx(st)
def logy(st='on'):
_validate_active()
_active.logy(st)
def xaxis(rng):
_validate_active()
_active.xaxis(rng)
def yaxis(rng):
_validate_active()
_active.yaxis(rng)
def zaxis(rng):
_validate_active()
_active.zaxis(rng)
def raxis(rng):
_validate_active()
_active.raxis(rng)
def taxis(rng):
_validate_active()
_active.taxis(rng)
def grid(st):
_validate_active()
_active.grid(st)
def hold(st):
_validate_active()
_active.hold(st)
def title(t):
_validate_active()
_active.title(t)
def xtitle(t):
_validate_active()
_active.xtitle(t)
def ytitle(t):
_validate_active()
_active.ytitle(t)
def ztitle(t):
_validate_active()
_active.ztitle(t)
def text(xyz,*t):
_validate_active()
apply(_active.text,(xyz,)+t )
def label_coord(c):
_validate_active()
_active.label_coord(c)
def legend(cmd=''):
_validate_active()
_active.legend(cmd)
#3d plotting stuff
def surf(*data):
_validate_active()
apply(_active.surf,data)
def plot3d(*data):
_validate_active()
apply(_active.plot3d,data)
def mapping(val):
_validate_active()
_active.mapping(val)
def angles(val):
_validate_active()
_active.angles(val)
def view(val):
_validate_active()
_active.view(val)
def ticlevel(val):
_validate_active()
_active.ticlevel(val)
def hidden(val):
_validate_active()
_active.hidden(val)
def output(filename,type,options = ''):
_validate_active()
_active.output(filename,type,options)
def png(filename):
_validate_active()
_active.png(filename)
def save(filename):
_validate_active()
_active.png(filename)
def size(size=(1.,1.)):
_validate_active()
_active.size(size)
|