def test_rcparams(self): # Test custom rcParams with rc_context({ 'axes.labelcolor': 'purple', 'axes.labelsize': 14, 'axes.labelweight': 'bold', 'axes.linewidth': 3, 'axes.facecolor': '0.5', 'axes.edgecolor': 'green', 'xtick.color': 'red', 'xtick.labelsize': 8, 'xtick.direction': 'in', 'xtick.minor.visible': True, 'xtick.minor.size': 5, 'xtick.major.size': 20, 'xtick.major.width': 3, 'xtick.major.pad': 10, 'grid.color': 'blue', 'grid.linestyle': ':', 'grid.linewidth': 1, 'grid.alpha': 0.5}): fig = plt.figure(figsize=(6, 6)) ax = WCSAxes(fig, [0.15, 0.1, 0.7, 0.7], wcs=None) fig.add_axes(ax) ax.set_xlim(-0.5, 2) ax.set_ylim(-0.5, 2) ax.grid() ax.set_xlabel('X label') ax.set_ylabel('Y label') ax.coords[0].set_ticklabel(exclude_overlapping=True) ax.coords[1].set_ticklabel(exclude_overlapping=True) return fig
def test_rcparams(self): # Test custom rcParams with rc_context({ 'axes.labelcolor': 'purple', 'axes.labelsize': 14, 'axes.labelweight': 'bold', 'axes.linewidth': 3, 'axes.facecolor': '0.5', 'axes.edgecolor': 'green', 'xtick.color': 'red', 'xtick.labelsize': 8, 'xtick.direction': 'in', 'xtick.minor.visible': True, 'xtick.minor.size': 5, 'xtick.major.size': 20, 'xtick.major.width': 3, 'xtick.major.pad': 10, 'grid.color': 'blue', 'grid.linestyle': ':', 'grid.linewidth': 1, 'grid.alpha': 0.5}): fig = plt.figure(figsize=(6, 6)) ax = WCSAxes(fig, [0.15, 0.1, 0.7, 0.7], wcs=None) fig.add_axes(ax) ax.set_xlim(-0.5, 2) ax.set_ylim(-0.5, 2) ax.grid() ax.set_xlabel('X label') ax.set_ylabel('Y label') ax.coords[0].set_ticklabel(exclude_overlapping=True) ax.coords[1].set_ticklabel(exclude_overlapping=True) return fig
def plot(self, center, width, s=None, c=None, marker=None, stride=1, emin=None, emax=None, label=None, fontsize=18, fig=None, ax=None, **kwargs): """ Plot event coordinates from this photon list in a scatter plot, optionally restricting the photon energies which are plotted and using only a subset of the photons. Parameters ---------- center : array-like The RA, Dec of the center of the plot in degrees. width : float, (value, unit) tuple, or :class:`~astropy.units.Quantity` The width of the plot in arcminutes. s : integer, optional Size of the scatter marker in points^2. c : string, optional The color of the points. marker : string, optional The marker to use for the points in the scatter plot. Default: 'o' stride : integer, optional Plot every *stride* events. Default: 1 emin : float, (value, unit) tuple, or :class:`~astropy.units.Quantity` The minimum energy of the photons to plot. Default is the minimum energy in the list. emax : float, (value, unit) tuple, or :class:`~astropy.units.Quantity` The maximum energy of the photons to plot. Default is the maximum energy in the list. label : string, optional The label of the spectrum. Default: None fontsize : int Font size for labels and axes. Default: 18 fig : :class:`~matplotlib.figure.Figure`, optional A Figure instance to plot in. Default: None, one will be created if not provided. ax : :class:`~matplotlib.axes.Axes`, optional An Axes instance to plot in. Default: None, one will be created if not provided. """ import matplotlib.pyplot as plt from astropy.visualization.wcsaxes import WCSAxes if fig is None: fig = plt.figure(figsize=(10, 10)) if ax is None: wcs = construct_wcs(center[0], center[1]) ax = WCSAxes(fig, [0.15, 0.1, 0.8, 0.8], wcs=wcs) fig.add_axes(ax) else: wcs = ax.wcs if emin is None: emin = self.energy.value.min() else: emin = parse_value(emin, "keV") if emax is None: emax = self.energy.value.max() else: emax = parse_value(emax, "keV") idxs = np.logical_and(self.energy.value >= emin, self.energy.value <= emax) ra = self.ra[idxs][::stride].value dec = self.dec[idxs][::stride].value x, y = wcs.wcs_world2pix(ra, dec, 1) ax.scatter(x, y, s=s, c=c, marker=marker, label=label, **kwargs) x0, y0 = wcs.wcs_world2pix(center[0], center[1], 1) width = parse_value(width, "arcmin") * 60.0 ax.set_xlim(x0 - 0.5 * width, x0 + 0.5 * width) ax.set_ylim(y0 - 0.5 * width, y0 + 0.5 * width) ax.set_xlabel("RA") ax.set_ylabel("Dec") ax.tick_params(axis='both', labelsize=fontsize) return fig, ax
def plot(self, center, width, s=None, c=None, marker=None, stride=1, emin=None, emax=None, label=None, fontsize=18, fig=None, ax=None, **kwargs): """ Plot event coordinates from this photon list in a scatter plot, optionally restricting the photon energies which are plotted and using only a subset of the photons. Parameters ---------- center : array-like The RA, Dec of the center of the plot in degrees. width : float, (value, unit) tuple, or :class:`~astropy.units.Quantity` The width of the plot in arcminutes. s : integer, optional Size of the scatter marker in points^2. c : string, optional The color of the points. marker : string, optional The marker to use for the points in the scatter plot. Default: 'o' stride : integer, optional Plot every *stride* events. Default: 1 emin : float, (value, unit) tuple, or :class:`~astropy.units.Quantity` The minimum energy of the photons to plot. Default is the minimum energy in the list. emax : float, (value, unit) tuple, or :class:`~astropy.units.Quantity` The maximum energy of the photons to plot. Default is the maximum energy in the list. label : string, optional The label of the spectrum. Default: None fontsize : int Font size for labels and axes. Default: 18 fig : :class:`~matplotlib.figure.Figure`, optional A Figure instance to plot in. Default: None, one will be created if not provided. ax : :class:`~matplotlib.axes.Axes`, optional An Axes instance to plot in. Default: None, one will be created if not provided. """ import matplotlib.pyplot as plt from astropy.visualization.wcsaxes import WCSAxes if fig is None: fig = plt.figure(figsize=(10, 10)) if ax is None: wcs = construct_wcs(center[0], center[1]) ax = WCSAxes(fig, [0.15, 0.1, 0.8, 0.8], wcs=wcs) fig.add_axes(ax) else: wcs = ax.wcs if emin is None: emin = self.energy.value.min() else: emin = parse_value(emin, "keV") if emax is None: emax = self.energy.value.max() else: emax = parse_value(emax, "keV") idxs = np.logical_and(self.energy.value >= emin, self.energy.value <= emax) ra = self.ra[idxs][::stride].value dec = self.dec[idxs][::stride].value x, y = wcs.wcs_world2pix(ra, dec, 1) ax.scatter(x, y, s=s, c=c, marker=marker, label=label, **kwargs) x0, y0 = wcs.wcs_world2pix(center[0], center[1], 1) width = parse_value(width, "arcmin")*60.0 ax.set_xlim(x0-0.5*width, x0+0.5*width) ax.set_ylim(y0-0.5*width, y0+0.5*width) ax.set_xlabel("RA") ax.set_ylabel("Dec") ax.tick_params(axis='both', labelsize=fontsize) return fig, ax