def plot_inter_order_mask(data, inter_order_mask): mask = data.T * inter_order_mask.T # Plot: fig, ax = plt.subplots(1, 1) im = ax.imshow(linear(data.T), cmap='Blues', origin='lower', alpha=1.0) im = ax.imshow(linear(mask), cmap='Blues', origin='lower', alpha=0.73) # Settings: ax.set_xlabel('Dispersion (pixels)') ax.set_ylabel('Cross (pixels)') # Colorbar: divider = make_axes_locatable(ax) cax = divider.append_axes('right', size='1.5%', pad=0.0) cbar = plt.colorbar(im, cax=cax) plt.ylabel('Norm. Counts') plt.show()
def plot_background_residuals(F_back, S_back, S): F = F_back / np.max(F_back) S = S_back / np.max(S_back) I = F - S fig, ax = plt.subplots(2, 1) # Plot: im0 = ax[0].imshow(linear(S.T), cmap='Blues', origin='lower') im1 = ax[1].imshow(I.T, vmin=np.min(I), vmax=np.max(I), cmap='Blues', origin='lower') # Settings: fig.subplots_adjust(hspace=-0.50) ax[0].set_xticklabels([]) ax[0].set_yticklabels(['', '', '200', '400']) # Colorbar ax0: cbar0 = fig.add_axes([0.9, 0.510, 0.015, 0.227]) cbar1 = fig.add_axes([0.9, 0.253, 0.015, 0.228]) fig.colorbar(im0, cax=cbar0) fig.colorbar(im1, cax=cbar1) # Labels: ax[0].annotate('(a)', xy=(50, 280), fontsize=15) ax[1].annotate('(b)', xy=(50, 280), fontsize=15) ax[1].set_xlabel('Dispersion (pixels)') ax[0].set_ylabel(r'Cross Dispersion (pixels)\qquad\qquad\qquad\tiny.') cbar0.set_ylabel('Norm. Counts') cbar1.set_ylabel('Residuals') plt.show()
def FITS(img, sigma=2, xlab=None, ylab=None, colorbar=None): """ Easy plot of pixel array data """ plt.figure() plt.imshow(linear(img, sigma), cmap='Blues', origin='lower') # Labels: if xlab is None and ylab is None: xlab, ylab = r'$x$ (pixel)', r'$y$ (pixel)' plt.xlabel(xlab) plt.ylabel(ylab) plt.show()
def plot_arc_scale(l_obs0, l_teo0, l_obs1, l_teo1, l, obs_results): """FIGURE MADE TO SPANS ENTIRE SCREEN""" # Unpack results from peak_finder: text, img, COF, radius = obs_results[0], obs_results[1], obs_results[ 2], obs_results[3] #---------- # SUBPLOTS: #---------- font = 17 fig = plt.figure() # 1. subplot: ax1 = fig.add_subplot(4, 1, (1, 3)) for i in range(len(l_obs0)): ax1.axvline(x=l_obs0[i], ymax=0.85, color='r', linestyle='--', alpha=1) for i in range(len(l_obs1)): ax1.axvline(x=l_obs1[i], ymax=0.85, color='r', linestyle='-', alpha=1) for i in range(len(l_teo0)): ax1.axvline(x=l_teo0[i], ymax=0.85, color='b', linestyle='--', alpha=1) for i in range(len(l_teo1)): ax1.axvline(x=l_teo1[i], ymax=0.85, color='b', linestyle='-', alpha=1) ax1.plot(l, img.sum(axis=1) / np.max(img.sum(axis=1)), 'k-', label='ThAr spectrum') # 2. subplot: ax2 = fig.add_subplot(313) ax2.imshow(linear(img.T), cmap='Blues') ax2.scatter(COF[:, 0], COF[:, 1], s=radius * 12, facecolors='none', edgecolors='r', marker='s') # Annotation: for i in range(len(l_teo0)): ax1.annotate(l_teo0[i], (l_teo0[i] - 0.5, 1.15), rotation=45, fontsize=11, color='b') # Labels: ax1.set_ylabel('Normalized Counts', fontsize=font) ax1.set_xlabel(r'$\lambda$ (Å)', fontsize=font) ax1.tick_params(labelsize=font) #------ #ax1.set_xticklabels([]) #ax2.set_yticklabels(['0', '']) ax2.set_xlabel(r'$\lambda$ (pixel)', fontsize=font) ax2.set_ylabel(r'$x$ (pixel)', fontsize=font) ax2.tick_params(labelsize=font) # Axes: ax1.set_xlim((min(l), max(l))) ax1.set_ylim((0, 1.2)) ax2.set_xlim((0, 2749)) ax2.invert_yaxis() plt.show()
def plot_optimal_extraction(img): # Prepare for scaled colorbar: gs = gridspec.GridSpec(1, 3) #------------ # 1. SUBPLOT: #------------ ax1 = plt.subplot2grid((2, 3), (0, 0), colspan=2) # Plot pixel image: #im = FITS(img.T, ax=ax1) im = ax1.imshow(linear(img.T), cmap='Blues', origin='lower') # Plot red and green boxes (given as cornerpoint and height and width): ax1.add_patch( Rectangle((7.5, -0.4), 1, len(img[:, 0]) - 0.3, fill=None, edgecolor='r', linewidth=1.2)) ax1.add_patch( Rectangle((29.5, -0.4), 1, len(img[:, 0]) - 0.3, fill=None, edgecolor='g', linewidth=1.2)) # Labels: ax1.set_xlabel(r'$\lambda$ (pixel)') ax1.set_ylabel(r'$x$ (pixel)') #------------ # 2. SUBPLOT: #------------ ax2 = plt.subplot2grid((9, 3), (0, 2), colspan=1, rowspan=5) # Cross cut in the image: l1 = img[:, 8] l2 = img[:, 10] #+100*np.ones(len(l1)) # Plot step plots: ax2.step(l1 / np.max(img), range(len(l1)), color='r') ax2.step(l2 / np.max(img), range(len(l2)), color='g') # Remove ticks and numbers from both axes: ax2.set_xticklabels([]) ax2.set_yticklabels([]) # Plot equation inside plot: ax2.text(-0.05, 6.5, r'$\sum\limits_x \text{P}_{x\lambda}=1$', fontsize=15) # Put colorbar from first plot as the x label (as they are shared): divider = make_axes_locatable(ax2) cax = divider.append_axes('bottom', size='10%', pad=0.0) # right, left, top, bottom cbar = plt.colorbar(im, cax=cax, orientation='horizontal') cbar.ax.set_xlabel('Normalized Counts') # Plot figure with small ajustment: plt.subplots_adjust(wspace=0, hspace=-0.03) plt.show()
def plot_background(data): # Plot: fig, ax = plt.subplots() im = ax.imshow(linear(data.T), cmap='Blues', origin='lower') # Settings: ax.set_xlabel('Dispersion (pixels)') ax.set_xticklabels([]) ax.set_ylabel(r'Cross Dispersion (pixels)') # Colorbar: divider = make_axes_locatable(ax) cax = divider.append_axes('right', size='3%', pad=0.0) cbar = plt.colorbar(im, cax=cax) plt.ylabel(r'Counts') plt.show()
def plot_arc_illustration(l_obs0, l_teo0, l_obs1, l_teo1, l, obs_results): """FIGURE MADE TO SPANS ENTIRE SCREEN""" # Unpack results from peak_finder: text, img, COF, radius = obs_results[0], obs_results[1], obs_results[ 2], obs_results[3] #---------- # SUBPLOTS: #---------- font = 12 fig = plt.figure() h = 0.85 # 1. subplot: ax1 = fig.add_subplot(10, 1, (1, 9)) for i in range(len(l_obs0)): ax1.axvline(x=l_obs0[i], ymax=h, color='r', linestyle=':', alpha=1) #for i in range(len(l_obs1)): ax1.axvline(x=l_obs1[i], ymax=0.85, color='r', linestyle='-', alpha=1) for i in range(len(l_teo0)): ax1.axvline(x=l_teo0[i], ymax=h, color='b', linestyle=':', alpha=1) for i in range(len(l_teo1)): ax1.axvline(x=l_teo1[i], ymax=h, color='limegreen', linestyle='-', alpha=1) ax1.plot(l, img.sum(axis=1) / np.max(img.sum(axis=1)), 'k-', label='ThAr spectrum') # 2. subplot: ax2 = fig.add_subplot(10, 1, 10) ax2.imshow(linear(img.T), cmap='Blues') ax2.scatter(COF[:, 0], COF[:, 1], s=radius * 12, facecolors='none', edgecolors='r', marker='s') #----------------- # GLOBAL SETTINGS: #----------------- # Legend: ax1.axvline(x=l_obs0[0], ymax=h, color='r', linestyle='--', alpha=0.4, label='COF') ax1.axvline(x=l_teo0[i], ymax=h, color='b', linestyle=':', alpha=1.0, label='Atlas lines') ax1.axvline(x=l_teo1[i], ymax=h, color='limegreen', linestyle='-', alpha=0.2, label='Final lines') ax1.legend(bbox_to_anchor=(0.93, 1.14), ncol=4, fontsize=font) # Annotation: for i in range(len(l_teo0)): ax1.annotate(l_teo0[i], (l_teo0[i] - 0.5, 1.15), rotation=45, fontsize=8, color='darkblue') # Labels: ax1.set_ylabel('Norm. Counts', fontsize=font) ax1.tick_params(labelsize=font) ax1.set_xticklabels([]) ax1.set_yticklabels(['', '', '0.2', '0.4', '0.6', '0.8', '1.0', '1.2']) #ax2.set_yticklabels(['0', '']) ax2.set_xlabel(r'$\lambda$ (pixel)', fontsize=font) ax2.set_ylabel(r'$\Delta x$', fontsize=font) ax2.tick_params(labelsize=font) # Axes: ax1.set_xlim((l[820], l[1850])) ax2.set_xlim((820, 1850)) ax1.set_ylim((-0.02, 1.2)) ax2.invert_yaxis() fig.subplots_adjust(hspace=-0.35) plt.show()