def PlotLikelihoods(measure='DM', model=model, typ='near', nside=nside, plot_every=1, absolute=False): ## plots evolution of likelihood function with z ## determine redshift to be plotted if typ == 'near': redshifts = redshift_skymaps_near[::plot_every] elif typ == 'far': redshifts = redshift_skymaps[::plot_every] ## plot likelihood function for each redshift color = cm.rainbow(np.linspace(0, 1, len(redshifts[1:]))) for z, c in zip(redshifts[1:], color): PlotLikelihood(z, measure=measure, typ=typ, model=model, nside=nside, absolute=absolute, color=c) ## care for labels plt.ylabel('P(%s|%s)' % (measure, 'd' if typ == 'near' else 'z')) plt.xlabel(r"%s (%s)" % (measure, units[measure])) if measure in ['DM', 'SM'] or absolute: plt.xscale('log') plt.yscale('log') plt.legend() ## save to file plt.savefig(root_likelihoods + '%s_%s_%s_likelihood.png' % (model, typ, '|%s|' % measure if absolute else measure)) plt.close()
def plot_spikes(df, sample_type, ax=None, mi=None, mx=None): if ax is None: fig, ax = plt.subplots() else: fig = None x = df[df['Sample Type'] == sample_type]['x'] y = df[df['Sample Type'] == sample_type]['z'] s = df[df['Sample Type'] == sample_type]['volume'] if mi is None: mi = min(s) mx = max(s) norm = np.array([((i - mi) / (mx - mi)) * 100 for i in s]) colors_to_use = cm.rainbow(norm / max(norm)) colmap = cm.ScalarMappable(cmap=cm.rainbow) colmap.set_array(colors_to_use) t = ax.scatter(x, y, c=colors_to_use, s=norm, marker='o') ax.set_xlim(150, 400) if fig is not None: fig.colorbar(colmap) return (fig, ax) return colmap
def plot_spike(df, spikename, ax=None, mi=None, mx=None): if ax is None: fig, ax = plt.subplots() x = df[df['Sample name'] == spikename]['x'] y = df[df['Sample name'] == spikename]['z'] s = df[df['Sample name'] == spikename]['volume'] if mi is None: mi = min(s) mx = max(s) norm = np.array([((i - mi) / (mx - mi)) * 75 for i in s]) colors_to_use = cm.rainbow(norm / max(norm)) colmap = cm.ScalarMappable(cmap=cm.rainbow) colmap.set_array(colors_to_use) ax.scatter(x, y, c=colors_to_use, s=norm, marker='o') ax.set_xlim(0, 512) fid = list(df[df['Sample name'] == spikename]['folderid'])[0] ax.set_title('{0}\n{1}'.format(spikename, fid)) # if fig: # fig.colorbar(colmap) # return (fig, ax) return colmap
def plot_av_image(av_image=None, header=None, title=None, limits=None, savedir='./', filename=None, show=True, av_mask=None, co_mask=None, av_threshold=None, av_thresholds=None): # Import external modules import matplotlib.pyplot as plt import matplotlib import numpy as np from mpl_toolkits.axes_grid1 import ImageGrid import pyfits as pf import matplotlib.pyplot as plt import pywcsgrid2 as wcs import pywcs from pylab import cm # colormaps from matplotlib.patches import Polygon import matplotlib.cm as cm import matplotlib.lines as mlines # Set up plot aesthetics plt.clf() plt.rcdefaults() colormap = plt.cm.gist_ncar #color_cycle = [colormap(i) for i in np.linspace(0, 0.9, len(flux_list))] fontScale = 15 params = {#'backend': .pdf', 'axes.labelsize': fontScale, 'axes.titlesize': fontScale, 'text.fontsize': fontScale, 'legend.fontsize': fontScale*3/4, 'xtick.labelsize': fontScale, 'ytick.labelsize': fontScale, 'font.weight': 500, 'axes.labelweight': 500, 'text.usetex': False, 'figure.figsize': (8, 7), 'figure.titlesize': fontScale #'axes.color_cycle': color_cycle # colors of different plots } plt.rcParams.update(params) # Create figure instance fig = plt.figure() nrows_ncols=(1,1) ngrids=1 imagegrid = ImageGrid(fig, (1,1,1), nrows_ncols=nrows_ncols, ngrids=ngrids, cbar_mode="each", cbar_location='right', cbar_pad="2%", cbar_size='3%', axes_pad=1, axes_class=(wcs.Axes, dict(header=header)), aspect=True, label_mode='L', share_all=True) # create axes ax = imagegrid[0] cmap = cm.pink # colormap cmap = cm.gray # colormap # show the image im = ax.imshow(av_image, interpolation='nearest',origin='lower', cmap=cmap, #norm=matplotlib.colors.LogNorm() ) # Asthetics ax.set_display_coord_system("fk4") ax.set_ticklabel_type("hms", "dms") ax.set_xlabel('Right Ascension (J2000)',) ax.set_ylabel('Declination (J2000)',) # colorbar cb = ax.cax.colorbar(im) cmap.set_bad(color='w') # plot limits if limits is not None: ax.set_xlim(limits[0],limits[2]) ax.set_ylim(limits[1],limits[3]) # Write label to colorbar cb.set_label_text(r'A$_V$ (Mag)',) # Show contour masks cs_co = ax.contour(co_mask, levels=(bad_pix,), origin='lower', colors='r', linestyles='-') if av_mask is not None: cs_av = ax.contour(av_mask, levels=(bad_pix,), origin='lower', colors='c', linestyles='solid') # Legend co_line = mlines.Line2D([], [], color='r', linestyle='--', label=r'CO threshold = 2$\times \sigma_{\rm CO}$') if av_thresholds is not None: colors = cm.rainbow(np.linspace(0, 1, len(av_thresholds))) for i, av_threshold in enumerate(av_thresholds): label = r'$A_V$ threshold = {0:1f} mag'.format(av_threshold) av_line = mlines.Line2D([], [], color=colors[i], linestyle='solid', label=label) elif av_threshold is not None and av_mask is not None: label = r'$A_V$ threshold = {0:1f} mag'.format(av_threshold) av_line = mlines.Line2D([], [], color='c', linestyle='solid', label=label) #ax.clabel(cs_co, inline=1, fontsize=10) #ax.clabel(cs_av, inline=1, fontsize=10) #cs_co.collections.set_label(r'CO threshold = 2$\times \sigma_{\rm CO}$') #cs_av.collections.set_label(r'$A_V$ threshold = ' + \ # '{0:1f} mag'.format(av_threshold)) lines = [cs_co.collections[0], cs_av.collections[0]] labels = [r'CO threshold = 2$\times\ \sigma_{\rm CO}$', r'$A_V$ threshold = {0:.1f} mag'.format(av_threshold)] ax.legend(lines, labels,) #bbox_to_anchor=(1,1), #loc=3, #ncol=2, #mode="expand", #borderaxespad=0.) if title is not None: fig.suptitle(title, fontsize=fontScale) if filename is not None: plt.savefig(savedir + filename, bbox_inches='tight') if show: fig.show()
def fig2_b(df_orig, ax=None, mi=None, mx=None, use_fig=False, fig=None): df = df_orig.copy(deep=True) mono_names = list( filter(lambda n: True if 'wild' not in n else False, einkorn['Sample name'].unique()))[:13] mono_names.extend( list( filter(lambda n: True if 'wild' in n else False, einkorn['Sample name'].unique()))) df = df[df['Sample name'].isin(mono_names)] df.ix[df['Sample Type'] == 'T. monococcum', 'x'] = df[df['Sample Type'] == 'T. monococcum']['x'] + 512 if ax is None: fig, ax = plt.subplots() x = df['x'] y = df['z'] s = df['volume'] if mi is None: mi = min(s) mx = max(s) norm = np.array([((i - mi) / (mx - mi)) * 100 for i in s]) colors_to_use = cm.rainbow(norm / max(norm)) colmap = cm.ScalarMappable(cmap=cm.rainbow) colmap.set_array(colors_to_use) t = ax.scatter(x, y, c=colors_to_use, s=norm, marker='o') if not use_fig: colbar = fig.colorbar(colmap, ticks=[0, 0.5, 1]) colbar.ax.set_yticklabels([ r'{0:3.2f}mm$^3$'.format(mi), r'{0:3.2f}mm$^3$'.format(df['volume'].mean()), r'{0:3.2f}mm$^3$'.format(mx) ]) x1 = [300, 800] squad = ['T. beoticum', 'T. monococcum'] ax.set_xticks(x1) ax.set_xticklabels(squad, minor=False) return (fig, ax) else: colbar = fig.colorbar(colmap, ticks=[0, 0.5, 1], ax=ax) colbar.ax.set_yticklabels([ r'{0:3.2f}mm$^3$'.format(mi), r'{0:3.2f}mm$^3$'.format(df['volume'].mean()), r'{0:3.2f}mm$^3$'.format(mx) ]) x1 = [300, 800] squad = ['T. beoticum', 'T. monococcum'] ax.set_xticks(x1) ax.set_xticklabels(squad, minor=False) return colmap
def plot_av_image(av_image=None, header=None, title=None, limits=None, savedir='./', filename=None, show=True, av_mask=None, co_mask=None, av_threshold=None, av_thresholds=None): # Import external modules import matplotlib.pyplot as plt import matplotlib import numpy as np from mpl_toolkits.axes_grid1 import ImageGrid import pyfits as pf import matplotlib.pyplot as plt import pywcsgrid2 as wcs import pywcs from pylab import cm # colormaps from matplotlib.patches import Polygon import matplotlib.cm as cm import matplotlib.lines as mlines # Set up plot aesthetics plt.clf() plt.rcdefaults() colormap = plt.cm.gist_ncar #color_cycle = [colormap(i) for i in np.linspace(0, 0.9, len(flux_list))] fontScale = 15 params = { #'backend': .pdf', 'axes.labelsize': fontScale, 'axes.titlesize': fontScale, 'text.fontsize': fontScale, 'legend.fontsize': fontScale * 3 / 4, 'xtick.labelsize': fontScale, 'ytick.labelsize': fontScale, 'font.weight': 500, 'axes.labelweight': 500, 'text.usetex': False, 'figure.figsize': (8, 7), 'figure.titlesize': fontScale #'axes.color_cycle': color_cycle # colors of different plots } plt.rcParams.update(params) # Create figure instance fig = plt.figure() nrows_ncols = (1, 1) ngrids = 1 imagegrid = ImageGrid(fig, (1, 1, 1), nrows_ncols=nrows_ncols, ngrids=ngrids, cbar_mode="each", cbar_location='right', cbar_pad="2%", cbar_size='3%', axes_pad=1, axes_class=(wcs.Axes, dict(header=header)), aspect=True, label_mode='L', share_all=True) # create axes ax = imagegrid[0] cmap = cm.pink # colormap cmap = cm.gray # colormap # show the image im = ax.imshow( av_image, interpolation='nearest', origin='lower', cmap=cmap, #norm=matplotlib.colors.LogNorm() ) # Asthetics ax.set_display_coord_system("fk4") ax.set_ticklabel_type("hms", "dms") ax.set_xlabel('Right Ascension (J2000)', ) ax.set_ylabel('Declination (J2000)', ) # colorbar cb = ax.cax.colorbar(im) cmap.set_bad(color='w') # plot limits if limits is not None: ax.set_xlim(limits[0], limits[2]) ax.set_ylim(limits[1], limits[3]) # Write label to colorbar cb.set_label_text(r'A$_V$ (Mag)', ) # Show contour masks cs_co = ax.contour(co_mask, levels=(bad_pix, ), origin='lower', colors='r', linestyles='-') if av_mask is not None: cs_av = ax.contour(av_mask, levels=(bad_pix, ), origin='lower', colors='c', linestyles='solid') # Legend co_line = mlines.Line2D([], [], color='r', linestyle='--', label=r'CO threshold = 2$\times \sigma_{\rm CO}$') if av_thresholds is not None: colors = cm.rainbow(np.linspace(0, 1, len(av_thresholds))) for i, av_threshold in enumerate(av_thresholds): label = r'$A_V$ threshold = {0:1f} mag'.format(av_threshold) av_line = mlines.Line2D([], [], color=colors[i], linestyle='solid', label=label) elif av_threshold is not None and av_mask is not None: label = r'$A_V$ threshold = {0:1f} mag'.format(av_threshold) av_line = mlines.Line2D([], [], color='c', linestyle='solid', label=label) #ax.clabel(cs_co, inline=1, fontsize=10) #ax.clabel(cs_av, inline=1, fontsize=10) #cs_co.collections.set_label(r'CO threshold = 2$\times \sigma_{\rm CO}$') #cs_av.collections.set_label(r'$A_V$ threshold = ' + \ # '{0:1f} mag'.format(av_threshold)) lines = [cs_co.collections[0], cs_av.collections[0]] labels = [ r'CO threshold = 2$\times\ \sigma_{\rm CO}$', r'$A_V$ threshold = {0:.1f} mag'.format(av_threshold) ] ax.legend( lines, labels, ) #bbox_to_anchor=(1,1), #loc=3, #ncol=2, #mode="expand", #borderaxespad=0.) if title is not None: fig.suptitle(title, fontsize=fontScale) if filename is not None: plt.savefig(savedir + filename, bbox_inches='tight') if show: fig.show()