def resetdefaults(): """ resetdefaults(): Reset global plotting variables to default values. """ global ppgplot_font_, ppgplot_linestyle_, ppgplot_linewidth_, \ ppgplot_color_, ppgplot_font_size_ ppgplot.pgscf(ppgplot_font_) ppgplot.pgsls(ppgplot_linestyle_) ppgplot.pgslw(ppgplot_linewidth_) ppgplot.pgsci(ppgplot_colors_[ppgplot_color_]) ppgplot.pgsch(ppgplot_font_size_)
def dm_time_plot(dms, times, sigmas, dm_arr, sigma_arr, time_arr, Total_observed_time, xwin): """ Plot DM vs Time subplot for the spd plots. Input: dms: list of dms of single pulse events to be plotted. times: list of times of single pulse events to be plotted. sigmas: list of sigmas of single pulse events to be plotted. dm_arr: array of dms of the main single pulse group (plotted in black). sigma_arr: array of sigmas of the main single pulse group (plotted in black). time_arr: array of times of single pulse group (plotted in black). Total_observed_time: float : Total observation time xwin: True or False. Use xwin or vcps window. """ min_dm = Num.min(dms) max_dm = Num.max(dms) ppgplot.pgswin(0, Total_observed_time, min_dm, max_dm) ppgplot.pgsch(0.8) ppgplot.pgslw(3) ppgplot.pgbox("BCNST", 0, 0, "BCNST", 0, 0) ppgplot.pgslw(3) ppgplot.pgmtxt('B', 2.5, 0.5, 0.5, "Time (s)") ppgplot.pgmtxt('L', 1.8, 0.5, 0.5, "DM (pc cm\\u-3\\d)") snr_range = 12.0 cand_symbols = [] cand_symbols_group = [] for i in range(len(sigmas)): if sigmas[i] > 20.00: sigmas[i] = 20.0 cand_symbol = int((sigmas[i] - 5.0) / snr_range * 6.0 + 20.5) cand_symbols.append(min(cand_symbol, 26)) cand_symbols = Num.array(cand_symbols) for i in range(len(dm_arr)): cand_symbol = int((sigma_arr[i] - 5.0) / snr_range * 6.0 + 20.5) cand_symbols_group.append(min(cand_symbol, 26)) cand_symbols_group = Num.array(cand_symbols_group) dms = Num.array(dms) times = Num.array(times) dm_arr = Num.array(dm_arr) time_arr = Num.array(time_arr) for ii in [26, 25, 24, 23, 22, 21, 20]: inds = Num.nonzero(cand_symbols == ii)[0] ppgplot.pgshls(1, 0.0, 0.5, 0.0) ppgplot.pgpt(times[inds], dms[inds], ii) for ii in [26, 25, 24, 23, 22, 21, 20]: inds_1 = Num.nonzero(cand_symbols_group == ii)[0] if xwin: ppgplot.pgshls(1, 0.0, 0.8, 0.0) else: ppgplot.pgshls(1, 0.0, 0.0, 0.0) ppgplot.pgpt(time_arr[inds_1], dm_arr[inds_1], ii)
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 isstr(color): 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 isstr(labels): 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 plotxy(y, x=None, title=None, rangex=None, rangey=None, \ labx='', laby='', rangex2=None, rangey2=None, \ labx2='', laby2='', symbol=ppgplot_symbol_, \ line=ppgplot_linestyle_, width=ppgplot_linewidth_, \ color=ppgplot_color_, font=ppgplot_font_, logx=0, logy=0, \ logx2=0, logy2=0, errx=None, erry=None, id=0, noscale=0, \ aspect=0.7727, fontsize=ppgplot_font_size_, ticks='in', \ panels=[1,1], device=ppgplot_device_, setup=1): """ plotxy(y, ...) An interface to make various XY style plots using PGPLOT. 'y' is the 1D sequence object to plot. The optional entries are: x: x values (default = 0, 1, ...) title: graph title (default = None) rangex: ranges for the x-axis (default = automatic) rangey: ranges for the y-axis (default = automatic) labx: label for the x-axis (default = None) laby: label for the y-axis (default = None) rangex2: ranges for 2nd x-axis (default = None) rangey2: ranges 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)) errx: symmetric x errors (default = None) erry: symmetric y errors (default = None) symbol: symbol for points (default = None) line: line style (default = 1 (solid)) width: line width (default = 1 (thin)) color: line and/or symbol color (default = 'white') 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 = 0.7727 (rect)) ticks: Ticks point in or out (default = 'in') panels: Number of subpanels [r,c] (default = [1,1]) device: PGPLOT device to use (default = '/XWIN') setup: Auto-setup the plot (default = 1) Note: Many default values are defined in global variables with names like ppgplot_font_ or ppgplot_device_. """ # Make sure the input data is an array y = Num.asarray(y) # Announce the global variables we will be using global ppgplot_dev_open_, ppgplot_dev_prep_, ppgplot_colors_ # Define the X axis limits if needed if x is None: x = Num.arange(len(y), dtype='f') else: x = Num.asarray(x) # Determine the scaling to use for the first axis if rangex is None: rangex = [x.min(), x.max()] if rangey is None: if noscale: rangey = [y.min(), y.max()] else: rangey = scalerange(y) # Prep the plotting device... if (not ppgplot_dev_prep_ and setup): prepplot(rangex, rangey, title, labx, laby, \ rangex2, rangey2, labx2, laby2, \ logx, logy, logx2, logy2, font, fontsize, \ id, aspect, ticks, panels, device=device) # Choose the line color if isstr(color): ppgplot.pgsci(ppgplot_colors_[color]) else: ppgplot.pgsci(color) # Plot symbols (and errors) if requested if not symbol is None: ppgplot.pgpt(x, y, symbol) # Error bars if errx is not None: if not logx: errx = Num.asarray(errx) ppgplot.pgerrx(x + errx, x - errx, y, 1.0) else: errx = 10.0**Num.asarray(errx) ppgplot.pgerrx(Num.log10(10.0**x + errx), Num.log10(10.0**x - errx), y, 1.0) if erry is not None: if not logy: erry = Num.asarray(erry) ppgplot.pgerry(x, y + erry, y - erry, 1.0) else: erry = 10.0**Num.asarray(erry) ppgplot.pgerry(x, Num.log10(10.0**y + erry), Num.log10(10.0**y - erry), 1.0) # Plot connecting lines if requested if not line is None: # Choose the line style ppgplot.pgsls(line) # Choose the line width ppgplot.pgslw(width) ppgplot.pgline(x, y)
def prepplot(rangex, rangey, title=None, labx=None, laby=None, \ rangex2=None, rangey2=None, labx2=None, laby2=None, \ logx=0, logy=0, logx2=0, logy2=0, font=ppgplot_font_, \ fontsize=ppgplot_font_size_, id=0, aspect=1, ticks='in', \ panels=[1,1], device=ppgplot_device_): """ prepplot(rangex, rangey, ...) Open a PGPLOT device for plotting. 'rangex' and 'rangey' are sequence objects giving min and max values for each axis. The optional entries are: title: graph title (default = None) labx: label for the x-axis (default = None) laby: label for the y-axis (default = None) rangex2: ranges for 2nd x-axis (default = None) rangey2: ranges 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)) 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)) aspect: Aspect ratio (default = 1 (square)) ticks: Ticks point in or out (default = 'in') 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_. """ global ppgplot_dev_open_, ppgplot_dev_prep_ # Check if we will use second X or Y axes # Note: if using a 2nd X axis, the range should correspond # to the minimum and maximum values of the 1st X axis. If # using a 2nd Y axis, the range should correspond to the # scalerange() values of the 1st Y axis. if rangex2 is None: rangex2 = rangex otherxaxis = 0 else: otherxaxis = 1 if rangey2 is None: rangey2 = rangey otheryaxis = 0 else: otheryaxis = 1 # Open the plot device if (not ppgplot_dev_open_): ppgplot.pgopen(device) # Let the routines know that we already have a device open ppgplot_dev_open_ = 1 # Set the aspect ratio ppgplot.pgpap(0.0, aspect) if (panels != [1, 1]): # Set the number of panels ppgplot.pgsubp(panels[0], panels[1]) ppgplot.pgpage() # Choose the font ppgplot.pgscf(font) # Choose the font size ppgplot.pgsch(fontsize) # Choose the font size ppgplot.pgslw(ppgplot_linewidth_) # Plot the 2nd axis if needed first if otherxaxis or otheryaxis: ppgplot.pgvstd() ppgplot.pgswin(rangex2[0], rangex2[1], rangey2[0], rangey2[1]) # Decide how the axes will be drawn if ticks == 'in': env = "CMST" else: env = "CMSTI" if logx2: lxenv = 'L' else: lxenv = '' if logy2: lyenv = 'L' else: lyenv = '' if otherxaxis and otheryaxis: ppgplot.pgbox(env + lxenv, 0.0, 0, env + lyenv, 0.0, 0) elif otheryaxis: ppgplot.pgbox("", 0.0, 0, env + lyenv, 0.0, 0) else: ppgplot.pgbox(env + lxenv, 0.0, 0, "", 0.0, 0) # Now setup the primary axis ppgplot.pgvstd() ppgplot.pgswin(rangex[0], rangex[1], rangey[0], rangey[1]) # Decide how the axes will be drawn if ticks == 'in': env = "ST" else: env = "STI" if logx: lxenv = 'L' else: lxenv = '' if logy: lyenv = 'L' else: lyenv = '' if otherxaxis and otheryaxis: ppgplot.pgbox("BN" + env + lxenv, 0.0, 0, "BN" + env + lyenv, 0.0, 0) elif otheryaxis: ppgplot.pgbox("BCN" + env + lxenv, 0.0, 0, "BN" + env + lyenv, 0.0, 0) elif otherxaxis: ppgplot.pgbox("BN" + env + lxenv, 0.0, 0, "BCN" + env + lyenv, 0.0, 0) else: ppgplot.pgbox("BCN" + env + lxenv, 0.0, 0, "BCN" + env + lyenv, 0.0, 0) # Add labels if not title is None: ppgplot.pgmtxt("T", 3.2, 0.5, 0.5, title) ppgplot.pgmtxt("B", 3.0, 0.5, 0.5, labx) ppgplot.pgmtxt("L", 2.6, 0.5, 0.5, laby) if otherxaxis: ppgplot.pgmtxt("T", 2.0, 0.5, 0.5, labx2) if otheryaxis: ppgplot.pgmtxt("R", 3.0, 0.5, 0.5, laby2) # Add ID line if required if (id == 1): ppgplot.pgiden() # Let the routines know that we have already prepped the device ppgplot_dev_prep_ = 1
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) ppgplot.pgclos()