def startPlotter(self): if self.plotDeviceIsOpened: raise ValueError("You already started a plot!") devId = pgplot.pgopen(self.deviceName) self.plotDeviceIsOpened = True if not self.widthInches is None: pgplot.pgpap(self.widthInches, self.yOnXRatio) # For devices /xs, /xw, /png etc, should make the paper white and the ink black. Only for /ps does pgplot default to that. # deviceWithoutFile = self.deviceName.split('/')[-1] if deviceWithoutFile == 'xs' or deviceWithoutFile == 'xw' or deviceWithoutFile == 'png': pgplot.pgscr(0, 1.0, 1.0, 1.0) pgplot.pgscr(1, 0.0, 0.0, 0.0) pgplot.pgsvp(self._vXLo, self._vXHi, self._vYLo, self._vYHi) if self.fixAspect: pgplot.pgwnad(self.worldXLo, self.worldXHi, self.worldYLo, self.worldYHi) else: pgplot.pgswin(self.worldXLo, self.worldXHi, self.worldYLo, self.worldYHi) pgplot.pgsfs(2) pgplot.pgslw(1) pgplot.pgsch(self._charHeight) self._setColourRepresentations() # Set up things so calling pgplot.pggray() won't overwrite the CR of any of the colours in self.colours. # (minCI, maxCI) = pgplot.pgqcir() if minCI <= self.maxCI: pgplot.pgscir(self.maxCI + 1, maxCI) (xLoPixels, xHiPixels, yLoPixels, yHiPixels) = pgplot.pgqvsz(3) (xLoInches, xHiInches, yLoInches, yHiInches) = pgplot.pgqvsz(1) self.xPixelWorld = (xHiInches - xLoInches) / (xHiPixels - xLoPixels) self.yPixelWorld = (yHiInches - yLoInches) / (yHiPixels - yLoPixels)
def reset_colors(): lo_col_ind, hi_col_ind = ppgplot.pgqcol() ppgplot.pgscir(lo_col_ind, hi_col_ind) ppgplot.pgscr(0, 0.00, 0.00, 0.00) # Black (background) ppgplot.pgscr(1, 1.00, 1.00, 1.00) # White (default) ppgplot.pgscr(2, 1.00, 0.00, 0.00) # Red ppgplot.pgscr(3, 0.00, 1.00, 0.00) # Green ppgplot.pgscr(4, 0.00, 0.00, 1.00) # Blue ppgplot.pgscr(5, 0.00, 1.00, 1.00) # Cyan (Green + Blue) ppgplot.pgscr(6, 1.00, 0.00, 1.00) # Magenta (Red + Blue) ppgplot.pgscr(7, 1.00, 1.00, 0.00) # Yellow (Red + Green) ppgplot.pgscr(8, 1.00, 0.50, 0.00) # Red + Yellow (Orange) ppgplot.pgscr(9, 0.50, 1.00, 0.00) # Green + Yellow ppgplot.pgscr(10, 0.00, 1.00, 0.50) # Green + Cyan ppgplot.pgscr(11, 0.00, 0.50, 1.00) # Blue + Cyan ppgplot.pgscr(12, 0.50, 0.00, 1.00) # Blue + Magenta ppgplot.pgscr(13, 1.00, 0.00, 0.50) # Red + Magenta ppgplot.pgscr(14, 0.33, 0.33, 0.33) # Dark Gray ppgplot.pgscr(15, 0.66, 0.66, 0.66) # Light Gray for ci in range(16, hi_col_ind + 1): ppgplot.pgscr(ci, 0.00, 0.00, 0.00) # Black (background)
def reset_colors(): lo_col_ind, hi_col_ind = ppgplot.pgqcol() ppgplot.pgscir(lo_col_ind, hi_col_ind) ppgplot.pgscr( 0, 0.00, 0.00, 0.00) # Black (background) ppgplot.pgscr( 1, 1.00, 1.00, 1.00) # White (default) ppgplot.pgscr( 2, 1.00, 0.00, 0.00) # Red ppgplot.pgscr( 3, 0.00, 1.00, 0.00) # Green ppgplot.pgscr( 4, 0.00, 0.00, 1.00) # Blue ppgplot.pgscr( 5, 0.00, 1.00, 1.00) # Cyan (Green + Blue) ppgplot.pgscr( 6, 1.00, 0.00, 1.00) # Magenta (Red + Blue) ppgplot.pgscr( 7, 1.00, 1.00, 0.00) # Yellow (Red + Green) ppgplot.pgscr( 8, 1.00, 0.50, 0.00) # Red + Yellow (Orange) ppgplot.pgscr( 9, 0.50, 1.00, 0.00) # Green + Yellow ppgplot.pgscr(10, 0.00, 1.00, 0.50) # Green + Cyan ppgplot.pgscr(11, 0.00, 0.50, 1.00) # Blue + Cyan ppgplot.pgscr(12, 0.50, 0.00, 1.00) # Blue + Magenta ppgplot.pgscr(13, 1.00, 0.00, 0.50) # Red + Magenta ppgplot.pgscr(14, 0.33, 0.33, 0.33) # Dark Gray ppgplot.pgscr(15, 0.66, 0.66, 0.66) # Light Gray for ci in range(16, hi_col_ind+1): ppgplot.pgscr(ci, 0.00, 0.00, 0.00) # Black (background)
def plot2d(z, x=None, y=None, title=None, rangex=None, rangey=None, \ rangez=None, labx='', laby='', rangex2=None, rangey2=None, \ labx2='', laby2='', image=ppgplot_palette_, contours=None, \ logx=0, logy=0, logx2=0, logy2=0, \ line=ppgplot_linestyle_, width=ppgplot_linewidth_, \ color=ppgplot_color_, labels=ppgplot_labels_, \ labelint=ppgplot_labelint_, labelmin=ppgplot_labelmin_, \ font=ppgplot_font_, id=0, noscale=0, aspect=1, \ fontsize=ppgplot_font_size_, ticks='out', panels=[1,1], \ device=ppgplot_device_): """ plot2d(z, ...) An interface to make various 2D plots using PGPLOT. 'z' is the 2D Numpy array to be plotted. The optional entries are: x: x values (default = 0, 1, ...) y: y values (default = 0, 1, ...) title: graph title (default = None) rangex: range for the x-axis (default = automatic) rangey: range for the y-axis (default = automatic) rangez: range for the z-axis (default = automatic) labx: label for the x-axis (default = None) laby: label for the y-axis (default = None) rangex2: range for 2nd x-axis (default = None) rangey2: range for 2nd y-axis (default = None) labx2: label for the 2nd x-axis (default = None) laby2: label for the 2nd y-axis (default = None) logx: make the 1st x-axis log (default = 0 (no)) logy: make the 1st y-axis log (default = 0 (no)) logx2: make the 2nd x-axis log (default = 0 (no)) logy2: make the 2nd y-axis log (default = 0 (no)) image: color palette for image (default = 'rainbow') contours: list of contour values (default = None) line: contour line style (default = 1 (solid)) width: contour line width (default = 1 (thin)) color: contour line color (default = 'white') labels: color of contour labels (default = None) labelint: contour label spacing (default = 20) labelmin: min contour label spacing (default = 20) font: PGPLOT font to use (default = 1 (normal)) fontsize: PGPLOT font size to use (default = 1.0 (normal)) id: show ID line on plot (default = 0 (no)) noscale: turn off auto scaling (default = 0 (no)) aspect: Aspect ratio (default = 1 (square)) ticks: Ticks point in or out (default = 'out') panels: Number of subpanels [r,c] (default = [1,1]) device: PGPLOT device to use (default = '/XWIN') Note: Many default values are defined in global variables with names like ppgplot_font_ or ppgplot_device_. """ # Make sure the input data is a 2D array z = Num.asarray(z); if not len(z.shape)==2: print 'Input data array must be 2 dimensional.' return # Announce the global variables we will be using global ppgplot_dev_open_, ppgplot_dev_prep_, pgpalette # Define the X and Y axis limits if needed if x is None: x=Num.arange(z.shape[1], dtype='f') else: x = Num.asarray(x) if y is None: y=Num.arange(z.shape[0], dtype='f') else: y = Num.asarray(y) # Determine the scaling to use for the axes if rangex is None: rangex=[Num.minimum.reduce(x), \ Num.maximum.reduce(x)] if rangey is None: rangey=[Num.minimum.reduce(y), \ Num.maximum.reduce(y)] if rangez is None: rangez=[Num.minimum.reduce(Num.ravel(z)), \ Num.maximum.reduce(Num.ravel(z))] # Prep the plotting device... if (not ppgplot_dev_prep_): prepplot(rangex, rangey, title, labx, laby, \ rangex2, rangey2, labx2, laby2, logx, logy, \ logx2, logy2, font, fontsize, id, aspect, \ ticks, panels, device=device) if image is not None: # Set the color indices and the color table lo_col_ind, hi_col_ind = ppgplot.pgqcol() lo_col_ind = lo_col_ind + 2 ppgplot.pgscir(lo_col_ind, hi_col_ind) pgpalette.setpalette(image) ppgplot.pgctab(pgpalette.l,pgpalette.r,pgpalette.g,pgpalette.b) # Construct the image ppgplot.pgimag_s(z, 0.0, 0.0, rangex[0], rangey[0], \ rangex[1], rangey[1]) reset_colors() if contours is not None: contours = Num.asarray(contours) # Choose the line style ppgplot.pgsls(line) # Choose the line width ppgplot.pgslw(width) # Choose the line color for the contourlines if type(color) == types.StringType: ppgplot.pgsci(ppgplot_colors_[color]) else: ppgplot.pgsci(color) # Construct the contours ppgplot.pgcont_s(z, len(contours), contours, rangex[0], \ rangey[0], rangex[1], rangey[1]) # Label the contours if requested if labels is not None: # Choose the line color for the contourlines if type(labels) == types.StringType: ppgplot.pgsci(ppgplot_colors_[labels]) else: ppgplot.pgsci(labels) for i in range(len(contours)): ppgplot.pgconl_s(z, contours[i], str(contours[i]), labelint, labelmin)
def plot2d(z, x=None, y=None, title=None, rangex=None, rangey=None, \ rangez=None, labx='', laby='', rangex2=None, rangey2=None, \ labx2='', laby2='', image=ppgplot_palette_, contours=None, \ logx=0, logy=0, logx2=0, logy2=0, \ line=ppgplot_linestyle_, width=ppgplot_linewidth_, \ color=ppgplot_color_, labels=ppgplot_labels_, \ labelint=ppgplot_labelint_, labelmin=ppgplot_labelmin_, \ font=ppgplot_font_, id=0, noscale=0, aspect=1, \ fontsize=ppgplot_font_size_, ticks='out', panels=[1,1], \ device=ppgplot_device_): """ plot2d(z, ...) An interface to make various 2D plots using PGPLOT. 'z' is the 2D Numpy array to be plotted. The optional entries are: x: x values (default = 0, 1, ...) y: y values (default = 0, 1, ...) title: graph title (default = None) rangex: range for the x-axis (default = automatic) rangey: range for the y-axis (default = automatic) rangez: range for the z-axis (default = automatic) labx: label for the x-axis (default = None) laby: label for the y-axis (default = None) rangex2: range for 2nd x-axis (default = None) rangey2: range for 2nd y-axis (default = None) labx2: label for the 2nd x-axis (default = None) laby2: label for the 2nd y-axis (default = None) logx: make the 1st x-axis log (default = 0 (no)) logy: make the 1st y-axis log (default = 0 (no)) logx2: make the 2nd x-axis log (default = 0 (no)) logy2: make the 2nd y-axis log (default = 0 (no)) image: color palette for image (default = 'rainbow') contours: list of contour values (default = None) line: contour line style (default = 1 (solid)) width: contour line width (default = 1 (thin)) color: contour line color (default = 'white') labels: color of contour labels (default = None) labelint: contour label spacing (default = 20) labelmin: min contour label spacing (default = 20) font: PGPLOT font to use (default = 1 (normal)) fontsize: PGPLOT font size to use (default = 1.0 (normal)) id: show ID line on plot (default = 0 (no)) noscale: turn off auto scaling (default = 0 (no)) aspect: Aspect ratio (default = 1 (square)) ticks: Ticks point in or out (default = 'out') panels: Number of subpanels [r,c] (default = [1,1]) device: PGPLOT device to use (default = '/XWIN') Note: Many default values are defined in global variables with names like ppgplot_font_ or ppgplot_device_. """ # Make sure the input data is a 2D array z = Num.asarray(z) if not len(z.shape) == 2: print 'Input data array must be 2 dimensional.' return # Announce the global variables we will be using global ppgplot_dev_open_, ppgplot_dev_prep_, pgpalette # Define the X and Y axis limits if needed if x is None: x = Num.arange(z.shape[1], dtype='f') else: x = Num.asarray(x) if y is None: y = Num.arange(z.shape[0], dtype='f') else: y = Num.asarray(y) # Determine the scaling to use for the axes if rangex is None: dx = x[-1] - x[-2] rangex = [x[0], x[-1] + dx] if rangey is None: dy = y[-1] - y[-2] rangey = [y[0], y[-1] + dy] if rangez is None: rangez=[Num.minimum.reduce(Num.ravel(z)), \ Num.maximum.reduce(Num.ravel(z))] # Prep the plotting device... if (not ppgplot_dev_prep_): prepplot(rangex, rangey, title, labx, laby, \ rangex2, rangey2, labx2, laby2, logx, logy, \ logx2, logy2, font, fontsize, id, aspect, \ ticks, panels, device=device) if image is not None: # Set the color indices and the color table lo_col_ind, hi_col_ind = ppgplot.pgqcol() lo_col_ind = lo_col_ind + 2 ppgplot.pgscir(lo_col_ind, hi_col_ind) pgpalette.setpalette(image) ppgplot.pgctab(pgpalette.l, pgpalette.r, pgpalette.g, pgpalette.b) # Construct the image ppgplot.pgimag_s(z, 0.0, 0.0, rangex[0], rangey[0], \ rangex[1], rangey[1]) reset_colors() if contours is not None: contours = Num.asarray(contours) # Choose the line style ppgplot.pgsls(line) # Choose the line width ppgplot.pgslw(width) # Choose the line color for the contourlines if type(color) == types.StringType: ppgplot.pgsci(ppgplot_colors_[color]) else: ppgplot.pgsci(color) # Construct the contours ppgplot.pgcont_s(z, len(contours), contours, rangex[0], \ rangey[0], rangex[1], rangey[1]) # Label the contours if requested if labels is not None: # Choose the line color for the contourlines if type(labels) == types.StringType: ppgplot.pgsci(ppgplot_colors_[labels]) else: ppgplot.pgsci(labels) for i in range(len(contours)): ppgplot.pgconl_s(z, contours[i], str(contours[i]), labelint, labelmin)
#fdot cut ppgplot.pgsvp(margin + imfract, 1.0 - margin / 2, margin, margin + imfract) ppgplot.pgswin(-0.1, 1.1, min(zs), max(zs)) ppgplot.pgbox("BCNST", 0.0, 0, "BCST", 0.0, 0) ppgplot.pgline(fdotcut, zs) ppgplot.pgmtxt("B", 2.4, 0.5, 0.5, "Relative Power") # f-fdot image ppgplot.pgsvp(margin, margin + imfract, margin, margin + imfract) ppgplot.pgswin(min(rs), max(rs), min(zs), max(zs)) ppgplot.pgmtxt("B", 2.4, 0.5, 0.5, labx) ppgplot.pgmtxt("L", 2.0, 0.5, 0.5, laby) lo_col_ind, hi_col_ind = ppgplot.pgqcol() lo_col_ind = lo_col_ind + 2 ppgplot.pgscir(lo_col_ind, hi_col_ind) pgpalette.setpalette(image) ppgplot.pgctab(pgpalette.l, pgpalette.r, pgpalette.g, pgpalette.b) ppgplot.pgimag_s(pffdot, 0.0, 0.0, rgx[0], rgy[0], rgx[1], rgy[1]) ppgplot.pgsci(1) ppgplot.pgcont_s(pffdot, len(contours), contours, rgx[0], rgy[0], rgx[1], rgy[1]) ppgplot.pgbox("BCST", 0.0, 0, "BCST", 0.0, 0) ppgplot.pgsci(1) ppgplot.pgbox("N", 0.0, 0, "N", 0.0, 0) # gray axes ppgplot.pgscr(1, 0.5, 0.5, 0.5) ppgplot.pgsci(1) ppgplot.pgslw(2) ppgplot.pgline(rgx, num.asarray([0.0, 0.0]))
#fdot cut ppgplot.pgsvp(margin+imfract, 1.0-margin/2, margin, margin+imfract) ppgplot.pgswin(-0.1, 1.1, min(zs), max(zs)) ppgplot.pgbox("BCNST", 0.0, 0, "BCST", 0.0, 0) ppgplot.pgline(fdotcut, zs) ppgplot.pgmtxt("B", 2.4, 0.5, 0.5, "Relative Power"); # f-fdot image ppgplot.pgsvp(margin, margin+imfract, margin, margin+imfract) ppgplot.pgswin(min(rs), max(rs), min(zs), max(zs)) ppgplot.pgmtxt("B", 2.4, 0.5, 0.5, labx); ppgplot.pgmtxt("L", 2.0, 0.5, 0.5, laby); lo_col_ind, hi_col_ind = ppgplot.pgqcol() lo_col_ind = lo_col_ind + 2 ppgplot.pgscir(lo_col_ind, hi_col_ind) pgpalette.setpalette(image) ppgplot.pgctab(pgpalette.l, pgpalette.r, pgpalette.g, pgpalette.b) ppgplot.pgimag_s(pffdot, 0.0, 0.0, rgx[0], rgy[0], rgx[1], rgy[1]) ppgplot.pgsci(1) ppgplot.pgcont_s(pffdot, len(contours), contours, rgx[0], rgy[0], rgx[1], rgy[1]) ppgplot.pgbox("BCST", 0.0, 0, "BCST", 0.0, 0) ppgplot.pgsci(1) ppgplot.pgbox("N", 0.0, 0, "N", 0.0, 0) # gray axes ppgplot.pgscr(1, 0.5, 0.5, 0.5) ppgplot.pgsci(1) ppgplot.pgslw(2) ppgplot.pgline(rgx, num.asarray([0.0, 0.0])) ppgplot.pgline(num.asarray([0.0, 0.0]), rgy)