1
#this just adds errorbar plotting capabilities
3
from numpy.lib.scimath import *
4
from types import StringType
10
dims = len(s) - sum(equal(1,s),axis=0)
11
new_s = compress(not_equal(1,s),s,axis=-1)
12
return reshape(a,new_s)
15
class Plot(pyPlot.Plot):
17
def errorbar(self,*data):
19
self._errorbar_plot(data)
21
def _errorbar_plot(self,data):
26
if not self.m_hold: self.errorbar_lt = 1
27
while len(remains) > 0:
28
group, remains = self._errorbar_get_plot_group(remains)
31
cmd, file = self._errorbar_prepare_plot(group)
32
except SizeMismatch, data:
33
print "Warning: ignoring plot group ", counter
34
print "The arrays should have the same number of " + data[0]
35
print 'array sizes: ', data[1],'and', data[2]
37
plotcmd = plotcmd + cmd
41
# if the plot command was valid, and we aren't
42
# adding to the current plot, delete all the old plot files
46
plotcmd = plotcmd[0:-2] # get rid of trailing comma
49
if(self.m_hold == 1 and len(self.m_tmpfiles) > 0):
50
self._send('replot ' + plotcmd)
52
self._send('plot ' + plotcmd)
53
self.m_tmpfiles = self.m_tmpfiles + tmpf
55
def _errorbar_prepare_plot(self, group):
64
#force 1D arrays to 2D columns
65
if(is1D(x) ): x = col(x)
66
if(is1D(y) ): y = col(y)
67
if(is1D(e) ): e = col(e)
71
#test that x and y have compatible shapes
72
#check that each array has the same number of rows
73
if(xs[0] != ys[0] or xs[0] != es[0]):
74
raise SizeMismatch, ('rows', xs, ys, es)
75
#check that x.cols = y.cols
76
#no error x has 1 column
77
if(xs[1] > 1 and (xs[1] != ys[1] or xs[1] !=es[1])):
78
raise SizeMismatch, ('cols', xs, ys, es)
80
raise SizeMismatch, ('cols', xs, ys, es)
81
#now write the data to a temp file and then plot it
82
filename = tempfile.mktemp()
83
f = open(filename, 'w')
86
mn,dummy = self._find_min_max(y-e)
87
dummy,mx = self._find_min_max(y+e)
95
for i in range(0,xs[0] ):
96
f.write( self._format( (x[i][0],) ))
97
for j in range(0,ys[1] ):
98
f.write( self._format( (y[i][j],e[i][j]) ))
100
for j in range(0,ys[1] ):
101
using = using + (' using 1:%d:%d' % (j+2,j+3),)
104
for i in range(0,xs[0] ):
105
for j in range(0,xs[1] ):
106
f.write( self._format( (x[i][j],y[i][j],e[i][j]) ) )
108
for j in range(0,xs[1] ):
109
using = using + (' using %d:%d:%d' % (j*2+1,j*2+2,j*2+3),)
111
#defualt to printing with lines
112
plotinfo = " notitle w lp lt " +`self.errorbar_lt` + ' '
114
# gnuplot doesn't seem to like backslashes
115
fn = string.replace(filename,'\\','/')
117
cmd = cmd + ' "' + fn + '" ' + us + 'notitle w errorbars lt ' +`self.errorbar_lt` + ', '
118
cmd = cmd + ' "' + fn + '" ' + us + plotinfo + ', '
119
self.errorbar_lt = (self.errorbar_lt + 1) % 15
122
def _errorbar_get_plot_group(self,data):
127
while(len(remains) > 0 and not finished):
136
if(type(el) == StringType):
143
if(type(el) != StringType):
145
group = group + (el,)
146
remains = remains[1:]
147
return group, remains