def plot_vs_years(tt, step = None, ax=None, confidence=None, ticks=True, **kwargs):
import matplotlib.pyplot as plt<EOL>tt.branch_length_to_years()<EOL>nleafs = tt.tree.count_terminals()<EOL>if ax is None:<EOL><INDENT>fig = plt.figure(figsize=(<NUM_LIT:12>,<NUM_LIT:10>))<EOL>ax = plt.subplot(<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>fig = None<EOL><DEDENT>if "<STR_LIT>" not in kwargs:<EOL><INDENT>kwargs["<STR_LIT>"] = lambda x:x.name if (x.is_terminal() and nleafs<<NUM_LIT:30>) else "<STR_LIT>"<EOL><DEDENT>Phylo.draw(tt.tree, axes=ax, **kwargs)<EOL>offset = tt.tree.root.numdate - tt.tree.root.branch_length<EOL>date_range = np.max([n.numdate for n in tt.tree.get_terminals()])-offset<EOL>if step is None or (step><NUM_LIT:0> and date_range/step><NUM_LIT:100>):<EOL><INDENT>step = <NUM_LIT:10>**np.floor(np.log10(date_range))<EOL>if date_range/step<<NUM_LIT:2>:<EOL><INDENT>step/=<NUM_LIT:5><EOL><DEDENT>elif date_range/step<<NUM_LIT:5>:<EOL><INDENT>step/=<NUM_LIT:2><EOL><DEDENT>step = max(<NUM_LIT:1.0>/<NUM_LIT:12>,step)<EOL><DEDENT>if step:<EOL><INDENT>dtick = step<EOL>min_tick = step*(offset//step)<EOL>extra = dtick if dtick<date_range else dtick<EOL>tick_vals = np.arange(min_tick, min_tick+date_range+extra, dtick)<EOL>xticks = tick_vals - offset<EOL><DEDENT>else:<EOL><INDENT>xticks = ax.get_xticks()<EOL>dtick = xticks[<NUM_LIT:1>]-xticks[<NUM_LIT:0>]<EOL>shift = offset - dtick*(offset//dtick)<EOL>xticks -= shift<EOL>tick_vals = [x+offset-shift for x in xticks]<EOL><DEDENT>ax.set_xticks(xticks)<EOL>ax.set_xticklabels(map(str, tick_vals))<EOL>ax.set_xlabel('<STR_LIT>')<EOL>ax.set_ylabel('<STR_LIT>')<EOL>ax.set_xlim((<NUM_LIT:0>,date_range))<EOL>if step:<EOL><INDENT>ylim = ax.get_ylim()<EOL>xlim = ax.get_xlim()<EOL>from matplotlib.patches import Rectangle<EOL>for yi,year in enumerate(np.arange(np.floor(tick_vals[<NUM_LIT:0>]), tick_vals[-<NUM_LIT:1>]+<NUM_LIT>, step)):<EOL><INDENT>pos = year - offset<EOL>r = Rectangle((pos, ylim[<NUM_LIT:1>]-<NUM_LIT:5>),<EOL>step, ylim[<NUM_LIT:0>]-ylim[<NUM_LIT:1>]+<NUM_LIT:10>,<EOL>facecolor=[<NUM_LIT>+<NUM_LIT:0.1>*(<NUM_LIT:1>+yi%<NUM_LIT:2>)] * <NUM_LIT:3>,<EOL>edgecolor=[<NUM_LIT:1>,<NUM_LIT:1>,<NUM_LIT:1>])<EOL>ax.add_patch(r)<EOL>if year in tick_vals and pos>=xlim[<NUM_LIT:0>] and pos<=xlim[<NUM_LIT:1>] and ticks:<EOL><INDENT>label_str = str(step*(year//step)) if step<<NUM_LIT:1> else  str(int(year))<EOL>ax.text(pos,ylim[<NUM_LIT:0>]-<NUM_LIT>*(ylim[<NUM_LIT:1>]-ylim[<NUM_LIT:0>]), label_str,<EOL>horizontalalignment='<STR_LIT>')<EOL><DEDENT><DEDENT>ax.set_axis_off()<EOL><DEDENT>if confidence:<EOL><INDENT>tree_layout(tt.tree)<EOL>if not hasattr(tt.tree.root, "<STR_LIT>"):<EOL><INDENT>print("<STR_LIT>")<EOL>return ttconf.ERROR<EOL><DEDENT>elif type(confidence) is float:<EOL><INDENT>cfunc = tt.get_max_posterior_region<EOL><DEDENT>elif len(confidence)==<NUM_LIT:2>:<EOL><INDENT>cfunc = tt.get_confidence_interval<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>")<EOL>return ttconf.ERROR<EOL><DEDENT>for n in tt.tree.find_clades():<EOL><INDENT>pos = cfunc(n, confidence)<EOL>ax.plot(pos-offset, np.ones(len(pos))*n.ypos, lw=<NUM_LIT:3>, c=(<NUM_LIT:0.5>,<NUM_LIT:0.5>,<NUM_LIT:0.5>))<EOL><DEDENT><DEDENT>return fig, ax<EOL>
Converts branch length to years and plots the time tree on a time axis.

Parameters
----------
 tt : TreeTime object
    A TreeTime instance after a time tree is inferred

 step : int
    Width of shaded boxes indicating blocks of years. Will be inferred if not specified.
    To switch off drawing of boxes, set to 0

 ax : matplotlib axes
    Axes to be used to plot, will create new axis if None

 confidence : tuple, float
    Draw confidence intervals. This assumes that marginal time tree inference was run.
    Confidence intervals are either specified as an interval of the posterior distribution
    like (0.05, 0.95) or as the weight of the maximal posterior region , e.g. 0.9

 **kwargs : dict
    Key word arguments that are passed down to Phylo.draw