hapsburg.figures.plot_timelines =============================== .. py:module:: hapsburg.figures.plot_timelines .. autoapi-nested-parse:: Main Inference Class for HMM. Wrapper for Inerence of Posterior. @ Author: Harald Ringbauer, 2019, All rights reserved Attributes ---------- .. autoapisummary:: hapsburg.figures.plot_timelines.lowess Functions --------- .. autoapisummary:: hapsburg.figures.plot_timelines.plot_scatter_by_color hapsburg.figures.plot_timelines.plot_violin_ax hapsburg.figures.plot_timelines.plot_lowess_smoothing hapsburg.figures.plot_timelines.lowess_sqrt hapsburg.figures.plot_timelines.fit_gp hapsburg.figures.plot_timelines.extract_pop hapsburg.figures.plot_timelines.prep_label hapsburg.figures.plot_timelines.extract_df_age hapsburg.figures.plot_timelines.plot_map_ax hapsburg.figures.plot_timelines.plot_colorbar_age hapsburg.figures.plot_timelines.plot_map_time Module Contents --------------- .. py:data:: lowess .. py:function:: plot_scatter_by_color(ax, age, roh, colors, labels, s, lw=1.0, ec='k', zorder=5, def_color='silver') Split up df per color, used to create legend (based on "clst" column). If default color (def_color) don't add label .. py:function:: plot_violin_ax(df, x=0, ax=0, figsize=(6, 6), cm=4, cm1=0, widths=50, ec='k', c='yellow', alpha=0.5, zorder=0, col_median='red', lw=0.4) Do a Violin Plot (usually on modern data) ax: If given plot on this Axis Object x: X Coordinate where to plot df: Dataframe containing on which x position to plot widths: With of the Violin .. py:function:: plot_lowess_smoothing(df, cm=4, cm1=0, fs=14, fsl=10, fs_leg=7, ec='k', lw=1.0, ticks=[3539.39 / 16, 3539.39 / 64], tick_l=['1st C.', '2nd C.'], figsize=(14, 6), title='', dpi=300, savepath='', xlim=[], ylim=[], s=40, frac=2 / 3, cust_c=True, lw_fit=2.5, width_t=2, length_t=6, yl_pad=0, labelpad=10, lw_hline=0.4, std_band=0, lgth_s=[500, 2000], err_s=[2, 4], max_f_age=0, t_offset=0, leg_loc='upper right', ax=0, swap_ax=True, show=True, xticks=False, rightcol=True) Plot Lowess Smoothing of ROH vrs Age. df: Which Dataframe to use [standard pp format] cm: Length of blocks to plot. cm1: Maximum block length to plot (if 0, none) savepath: If given save figure to there tot_l: Total length of accessible Chromosome [in cM] frac: Fraction Parameter to use for Lowess Smoothing. leg_loc: Where to plot the Legend. If no string given do not plot at all swap_ax: Whether to swap left/right tick axis std_band: How many standard deviations to plot (1.96. is 95%). If >0 use gp model lght_s: Length Scale of Gaussian Kernel to fit err_s: Error Scale of Gaussian Kernel to fit max_f_age: Maximum Age of sample to include in GP fs/fsl: Fontsize Axis / Fontsize Legend/Cousin Ticks lw: Linewidth in the Scatter Plot points ec: Edge Color of Scatter Plot points t_offset: Vertical Offset of the Ne/Cousin Text width_t, length_t: Width and Length of Axis Ticks yl_pad: Tick Label Pad of y Axis .. py:function:: lowess_sqrt(x, y, frac=2 / 3) Do a Lowess fitting on the sqrt. frac: parameter for lowess smoothing .. py:function:: fit_gp(x, y, sqrt=True, in_lengthscale=1000, in_noise=2.0, std_band=1.96, lgth_s=[500, 2000], err_s=[2, 4]) Fit Gaussian Process. If sqrt: Take the square root for fit. Return: x, y, y_max, y_min .. py:function:: extract_pop(df, age_range=[], pop='', col='region') Assumes plotting Dataframe is pre-produced. Return Legend as well .. py:function:: prep_label(df, pop, only_anc=True) Prepare a label string to use in legend. pop: Population that's going to be used [string] only_anc: Whether to only count ancients .. py:function:: extract_df_age(df, age0, age1=1000000.0) Extract Dataframe based on age. df: Input Dataframe; age0 and age1 min and max age .. py:function:: plot_map_ax(df, ax, crs=[30, 60, -10, 40], s=40, vrange=[0, 7500], cmap='viridis_r', map_title='', title_loc=(0.1, 0.1), lw=1.0, ec='k', fs_label=14, figsize=(12, 11), states=False, countries=False, annotate=False, fs_labels=14, ew=0.5, y_off=1, title='', plot_mod=True, vrange_a=[], mm=3.1, hspace=0.02, fs=18, col_cont='#d9d9d9', col_lake='#d9d9d9', show=True, lw_coast=0.5, res='i') Plot a continent, based on coordinates in df df: Pandas Datframe with lat lon column crs: [4], Corners of plot (lat and then lon) vrange: Normalization range for color [cM] shiftlong: Add to longitude (in cases for map on South America) vrange_a: The Age Range to Plot col_cont: Color of the Continent: "#d9d9d9" is very faint gray from Sardinia paper lw: Width of Scatter point edges ec: Color of Scatter point edges res: Resolution of Coastline: c l m i h .. py:function:: plot_colorbar_age(ax, fs_label, cmap, vrange, xlim=[], labelpad=10, invert=True, bottomrow=True, width_t=2, length_t=6, xl_pad=0) Code for plotting a colorbar of age onto axis Object .. py:function:: plot_map_time(df, figsize=(20, 4), width_ratios=[1, 10], height_ratios=[20, 1], wspace=0.02, hspace=0.03, ec='k', lw=1.0, title_tl='', s_tl=80, x_lim_tl=[-100, 10000], y_lim_tl=[0, 550], widths=50, alpha_vio=0.5, lw_fit=2.5, width_t=2, length_t=6, lw_coast=0.5, ticks=[3539.39 / 16, 3539.39 / 64], tick_l=['1st C.', '2nd C.'], max_f_age=0, leg_loc_tl='upper center', frac=0.8, cm=4, cm1=0, fs=10, fsl=10, fs_leg=7, std_band=1.96, lgth_s=[2000, 5000], err_s=[2, 4], vrange_m=[], cmap_m='viridis_r', crs_m=[30, 60, -10, 40], lbl_pad_age=10, lbl_pad_time=5, map_title='', title_loc=(0.1, 0.1), bottomrow=True, rightcol=True, xl_pad=4, yl_pad=4, plot_mod=False, savepath='') Plot Map (Left) and Timeline (Right) df: Dataframe with input data on individual block sharing: Columns for sum>cm, age, and color _tl Arguments: Arguments for the Timeline. fs, fsl, fs_leg: Fontsize (general, labels & legend) cm: Minimum Block length shown cm1: Maximum Block length. (if 0 none) frac: Fraction for Lowess Smoothin (if 0 no lowess smoothing shown) savepath: Where to save (if empty string, nothing is saved) cmap_m, vrange_m: Color Map (Keyword which one to use) and Range for Map Plots crs_m: Corners for the Map (Lat0, Lat1, Lon0, Lon1)-Vector lgth_s: Length scale of the Kerne to fit std_band: Standard Deviation of Estimate to plot. If 0, no GP confidence band is shown. ec: Edge Color of Scatter Plots lw: Line Width of Scatter Plots bottomrow: Whether plot is in bottom (plot xlabel then) rightcol: Same, but whether plot on right (plot ylabel then) alpha_vio: Alpha of the Violing Plot width: Width of Violin Plot for moderns lw_fit: Line Width of fitted line width_t, length_t: Width and Length of Ticks xl_pad, yl_pad: Label Pads of x and y Axis