def plot(self, outfile=''): """Make a nice plot of a light curve. If outfile == '', make up a name; if outfile is None, don't save.""" #Check to make sure the data exists try: assert (self.data[0, 0, 0] is not None) except AssertionError: print( 'No data yet! Must run build_light_curve before we can plot.') xlo = self.data[:, 0, 0].astype('float') xhi = self.data[:, 0, 1].astype('float') x = .5 * (xlo + xhi) for i in xrange(self.data.shape[1]): name = self.data[0, i, 2] if outfile == '': outfile = '%s_lightcurve_%i-%i.png' % ( name.replace(' ', '_'), self.factory_kwargs['tstart'], self.factory_kwargs['tstop']) y, yhi, ylo = self.data[:, i, 3:6].astype('float').transpose() #mask = (y>1e-11)&(ylo<y)&~np.isnan(ylo) mask = ylo > 0 ax = pl.gca() ax.plot([xlo[mask], xhi[mask]], [y[mask]] * 2, color='r', linewidth=1) ax.plot([x[mask]] * 2, [ylo[mask], yhi[mask]], color='r', linewidth=1) nmask = ~mask ax.plot([xlo[nmask], xhi[nmask]], [yhi[nmask]] * 2, color='k', linewidth=1) ax.set_xbound(xlo[0] - 86400, xhi[-1] + 86400) ticks = ax.get_xticks() labels = [] labels = [MET(t).time.isoformat()[:10] for t in ticks] ax.set_xticklabels(labels) pl.title('Light Curve for %s' % name) ax.set_ylabel(r'Flux (10^-6 ph cm^-2 s^-1)') if outfile is not None: pl.savefig(outfile) pl.delaxes(ax)
def alt_plt(self, axis_num, x, y, style): pylab.delaxes(self.ax2) ax = pylab.subplot(axis_num) ax.plot(x, y, **style)
def plot(self, matrix, RHSvector, log='auto'): import tempfile import os (f, mtxName) = tempfile.mkstemp(suffix='.mtx') matrix.exportMmf(mtxName) mtx = mmio.mmread(mtxName) ## f.close() os.remove(mtxName) pylab.ion() c = mtx.tocoo() y = c.row x = c.col z = c.data b = RHSvector if len(z) == 0: y = zeros((1,)) x = zeros((1,)) z = zeros((1,)) zPlus = where(z > 0, log10(z), nan) zMinus = where(z < 0, log10(-z), nan) bPlus = where(b > 0, log10(b), nan) bMinus = where(b < 0, log10(-b), nan) if (log == True or (log == 'auto' and (max(zPlus) - min(zPlus) > 2 or max(zMinus) - min(zMinus) > 2 or max(bPlus) - min(bPlus) > 2 or max(bMinus) - min(bMinus) > 2))): log = True else: log = False if log: zMin = nanmin((nanmin(zPlus), nanmin(zMinus), nanmin(bPlus), nanmin(bMinus))) zMax = nanmax((nanmax(zPlus), nanmax(zMinus), nanmax(bPlus), nanmax(bMinus))) ## zThreshold = 0.5 # (zMax - zMin) / 5. zMin -= 0.5 numdec = math.floor(zMax)-math.ceil(zMin) if numdec < 0: zMax += 0.5 zPlus -= zMin zMinus -= zMin bPlus -= zMin bMinus -= zMin zRange = zMax - zMin if zRange == 0: zRange = nanmax(zPlus) + 1 z = where(z > 0, zPlus, -zMinus) z = where(isnan(z), 0., z) b = where(b > 0, bPlus, -bMinus) b = where(isnan(b), 0., b) fmt = SignedLogFormatter(threshold=zMin) loc = SignedLogLocator(threshold=zMin) else: zRange = max(max(abs(z)), max(abs(b))) if zRange == 0: zRange = 1 fmt = None loc = None N = matrix._getShape()[0] saveSize = pylab.rcParams['figure.figsize'] size = pylab.rcParams['figure.dpi'] **2 * saveSize[0] * saveSize[1] / N**2 pylab.ioff() pylab.figure(self.id) pylab.clf() pylab.delaxes() ax1 = pylab.axes([self.margin, self.margin, self.width, self.width]) Mscat = pylab.scatter(x, y, c=z, vmin=-zRange, vmax=zRange, edgecolors='none', cmap=pylab.get_cmap('RdBu'), marker='s', s=size) ax2 = pylab.axes([self.width + self.margin, self.margin, (self.width / self.aspect) / N, self.width], sharey=ax1) bscat = pylab.scatter(zeros((N,)), arange(N), c=b, vmin=-zRange, vmax=zRange, edgecolors='none', cmap=pylab.get_cmap('RdBu'), marker='s', s=size) pylab.setp((ax2.get_xticklabels(), ax2.get_yticklabels(), ax2.get_xticklines(), ax2.get_yticklines()), visible=False) pylab.axes(ax1) pylab.axis([-0.5, N - 0.5, N - 0.5, -0.5]) pylab.colorbar(format=fmt, ticks=loc) pylab.title(self.title) pylab.draw()