def plot(self, num_pointsx=100, num_pointsy=100, num_contours=75, logz=False, show=True): """Plot the spline. Args ---- num_pointsx : int The number of x sampling points to be used to draw the spline. num_pointsy : int The number of y sampling points to be used to draw the spline. num_contours : int The number of contours for the color plot. show : bool, optional If True, `plt.show()` is called at the end, interrupting the flow. """ from ximpol.utils.matplotlib_ import pyplot as plt _x = numpy.linspace(self.xmin(), self.xmax(), num_pointsx) _y = numpy.linspace(self.ymin(), self.ymax(), num_pointsy) _x, _y = numpy.meshgrid(_x, _y) _z = self(_x, _y, grid=False) if logz: from matplotlib.colors import LogNorm _levels = numpy.logspace(-4, numpy.log10(_z.max()), num_contours) contour = plt.contourf(_x, _y, _z, levels=_levels, norm=LogNorm()) else: contour = plt.contourf(_x, _y, _z, num_contours) bar = plt.colorbar() if self.xname is not None: plt.xlabel(self.xlabel()) if self.yname is not None: plt.ylabel(self.ylabel()) if self.zname is not None: bar.set_label(self.zlabel()) if show: plt.show()
def plot_pol_map_from_ascii(): output_file = get_output_file() logger.info('Opening file %s for plotting...' % output_file) emin,emax, degree, degree_error, angle, angle_error, counts = numpy.loadtxt(output_file, delimiter=',', unpack=True) _ra = numpy.linspace(ra_min, ra_max, num_points) _dec = numpy.linspace(dec_min, dec_max, num_points) _ra, _dec = numpy.meshgrid(_ra, _dec) fig = plt.figure() for i in range(len(E_BINNING) - 1): sigma_array = degree[emin==E_BINNING[i]]/degree_error[emin==E_BINNING[i]] pol_array = degree[emin==E_BINNING[i]].reshape((num_points,num_points)) sigma_array = sigma_array.reshape((num_points,num_points)) ax1 = fig.add_subplot() label = 'XIPE %.1d ks'%(DURATION/1000.) plt.contourf(_ra,_dec,pol_array) cbar = plt.colorbar() cbar.ax.set_ylabel('Polarization degree') plt.text(0.02, 0.92, label, transform=plt.gca().transAxes, fontsize=20,color='w') plt.xlabel('RA') plt.ylabel('DEC') # fig.gca().add_artist(psf) plt.show() ax2 = fig.add_subplot() plt.contourf(_ra,_dec,sigma_array) cbar2 = plt.colorbar() cbar2.ax.set_ylabel('Sigma') plt.text(0.02, 0.92, label, transform=plt.gca().transAxes, fontsize=20,color='w') plt.xlabel('RA') plt.ylabel('DEC') plt.show()
def plot(self, num_pointsx=100, num_pointsy=100, num_contours=75, logz=False, show=True): """Plot the spline. Args ---- num_pointsx : int The number of x sampling points to be used to draw the spline. num_pointsy : int The number of y sampling points to be used to draw the spline. num_contours : int The number of contours for the color plot. show : bool, optional If True, `plt.show()` is called at the end, interrupting the flow. """ from ximpol.utils.matplotlib_ import pyplot as plt _x = numpy.linspace(self.xmin(), self.xmax(), num_pointsx) _y = numpy.linspace(self.ymin(), self.ymax(), num_pointsy) _x, _y = numpy.meshgrid(_x, _y) _z = self(_x, _y, grid=False) if logz: from matplotlib.colors import LogNorm _levels = numpy.logspace(-4, numpy.log10(_z.max()), num_contours) contour = plt.contourf(_x, _y, _z, levels=_levels, norm = LogNorm()) else: contour = plt.contourf(_x, _y, _z, num_contours) bar = plt.colorbar() if self.xname is not None: plt.xlabel(self.xlabel()) if self.yname is not None: plt.ylabel(self.ylabel()) if self.zname is not None: bar.set_label(self.zlabel()) if show: plt.show()