예제 #1
0
def plotst(y, titlestr):
	n = min(minimum.reduce(y))
	m = max(maximum.reduce(y))
	nlevels = 40
	clevel = linspace(n, m, nlevels)
	ticks, mticks = scale1(clevel[0], clevel[-1])
	time = linspace(start / srate, end / srate, y.shape[1])
	fr = linspace(lo, hi, y.shape[0])
	if ref:
		subplot(211)
	c = contourf(time, fr, y, clevel, cmap = cm.jet)
	cax = gca()
	title(titlestr, fontsize = 15)
	colorbar(format = '%.2g', ticks = ticks)
	newright = cax.get_position()[2]
	if ref:
		from matplotlib.colorbar import make_axes
		subplot(212)
		plot(time, r)
		# ensure the x axis takes up the same amount of space
		ax = gca()
		p = ax.get_position()
		p[2] = newright
		ax.set_position(p)
		# ensure the x axis has the same range
		a = list(ax.axis())
		a[0:2] = cax.axis()[0:2]
		ax.axis(a)
예제 #2
0
    def plot(self, z, cmap=meg_cmap, zrange="zero", label=False, showsens=False):
        """The array z of values to be plotted must be in the same
	order as the array returned by get_names(). zrange can be
	'auto', 'zero' which is auto but symmetric around 0, or
	a pair of min, max."""

        make_spline(self.x, self.y, array(z, "d"))
        r = range(self.M)
        for i in r:
            xx = self.X[i]
            for j in r:
                yy = self.Y[j]
                if not self.mask[j, i]:
                    self.Z[j, i] = interpolate(xx, yy, self.x, self.y)

        Z = ma.array(self.Z, mask=self.mask)

        if zrange == "auto" or zrange == "zero":
            zmin = ma.minimum.reduce(Z)
            zmax = ma.maximum.reduce(Z)
            if zrange == "zero":
                # If it crosses zero make it symmetrical.
                if (zmin < 0) and (0 < zmax):
                    maxmax = max(-zmin, zmax)
                    zmin = -maxmax
                    zmax = maxmax
        else:
            zmin = zrange[0]
            zmax = zrange[1]

        # First make nice tics for this range.
        # Then switch to the new limits given by the tics
        # so the contour plot will use the whole range.
        ticks, mticks = scale1(zmin, zmax)
        zmin, zmax = ticks[0], ticks[-1]

        nlevels = 100
        levels = linspace(zmin, zmax, nlevels)

        # plot the boundary and maybe the sensors
        plot(self.boundx, self.boundy, color="black", zorder=1, linewidth=3)
        if showsens:
            scatter(self.x, self.y, s=15, c=(0, 1, 0), zorder=2, marker="o", linewidth=0.5)

        #        contourf(self.X, self.Y, Z, levels, cmap = cmap)
        #        contourf(self.X, self.Y, Z, levels, cmap = matplotlib.cm.hot)
        contourf(self.X, self.Y, Z, levels)
        im = gci()  # save the ContourSet to return
        contour(self.X, self.Y, Z, 10, colors="black")

        if label:
            for name in self.sensors:
                s = self.topo[name]
                text(s.x, s.y, name)

        l = 1.02
        x = -0.01
        y = -0.04
        axis([x, x + l, y, y + l])
        axis("off")
        axis("scaled")
        return im, ticks