def adjust_text(texts, x=None, y=None, add_objects=None, ax=None,<EOL>expand_text=(<NUM_LIT>, <NUM_LIT>), expand_points=(<NUM_LIT>, <NUM_LIT>),<EOL>expand_objects=(<NUM_LIT>, <NUM_LIT>), expand_align=(<NUM_LIT>, <NUM_LIT>),<EOL>autoalign='<STR_LIT>',  va='<STR_LIT>', ha='<STR_LIT>',<EOL>force_text=(<NUM_LIT:0.1>, <NUM_LIT>), force_points=(<NUM_LIT>, <NUM_LIT:0.5>),<EOL>force_objects=(<NUM_LIT:0.1>, <NUM_LIT>),<EOL>lim=<NUM_LIT>, precision=<NUM_LIT>,<EOL>only_move={'<STR_LIT>':'<STR_LIT>', '<STR_LIT:text>':'<STR_LIT>', '<STR_LIT>':'<STR_LIT>'},<EOL>avoid_text=True, avoid_points=True, avoid_self=True,<EOL>save_steps=False, save_prefix='<STR_LIT>', save_format='<STR_LIT>',<EOL>add_step_numbers=True, on_basemap=False,<EOL>*args, **kwargs):
plt.draw()<EOL>if ax is None:<EOL><INDENT>ax = plt.gca()<EOL><DEDENT>r = get_renderer(ax.get_figure())<EOL>orig_xy = [get_text_position(text, ax=ax) for text in texts]<EOL>orig_x = [xy[<NUM_LIT:0>] for xy in orig_xy]<EOL>orig_y = [xy[<NUM_LIT:1>] for xy in orig_xy]<EOL>force_objects = float_to_tuple(force_objects)<EOL>force_text = float_to_tuple(force_text)<EOL>force_points = float_to_tuple(force_points)<EOL><INDENT>xdiff = np.diff(ax.get_xlim())[<NUM_LIT:0>]<EOL>ydiff = np.diff(ax.get_ylim())[<NUM_LIT:0>]<EOL><DEDENT>bboxes = get_bboxes(texts, r, (<NUM_LIT:1.0>, <NUM_LIT:1.0>), ax)<EOL>sum_width = np.sum(list(map(lambda bbox: bbox.width, bboxes)))<EOL>sum_height = np.sum(list(map(lambda bbox: bbox.height, bboxes)))<EOL>if not any(list(map(lambda val: '<STR_LIT:x>' in val, only_move.values()))):<EOL><INDENT>precision_x = np.inf<EOL><DEDENT>else:<EOL><INDENT>precision_x = precision*sum_width<EOL><DEDENT>if not any(list(map(lambda val: '<STR_LIT:y>' in val, only_move.values()))):<EOL><INDENT>precision_y = np.inf<EOL><DEDENT>else:<EOL><INDENT>precision_y = precision*sum_height<EOL><DEDENT>if x is None:<EOL><INDENT>if y is None:<EOL><INDENT>if avoid_self:<EOL><INDENT>x, y = orig_x, orig_y<EOL><DEDENT>else:<EOL><INDENT>x, y = [], []<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>if y is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if add_objects is None:<EOL><INDENT>text_from_objects = False<EOL>add_bboxes = []<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>add_bboxes = get_bboxes(add_objects, r, (<NUM_LIT:1>, <NUM_LIT:1>), ax)<EOL><DEDENT>except:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL>return<EOL><DEDENT>text_from_objects = True<EOL><DEDENT>for text in texts:<EOL><INDENT>text.set_va(va)<EOL>text.set_ha(ha)<EOL><DEDENT>if save_steps:<EOL><INDENT>if add_step_numbers:<EOL><INDENT>plt.title('<STR_LIT>')<EOL><DEDENT>plt.savefig('<STR_LIT>' % (save_prefix,<EOL>'<STR_LIT>', save_format), format=save_format, dpi=<NUM_LIT>)<EOL><DEDENT>elif on_basemap:<EOL><INDENT>ax.draw(r)<EOL><DEDENT>if autoalign:<EOL><INDENT>if autoalign is True:<EOL><INDENT>autoalign='<STR_LIT>'<EOL><DEDENT>for i in range(<NUM_LIT:2>):<EOL><INDENT>texts = optimally_align_text(x, y, texts, expand=expand_align,<EOL>add_bboxes=add_bboxes,<EOL>direction=autoalign, renderer=r,<EOL>ax=ax)<EOL><DEDENT><DEDENT>if save_steps:<EOL><INDENT>if add_step_numbers:<EOL><INDENT>plt.title('<STR_LIT>')<EOL><DEDENT>plt.savefig('<STR_LIT>' % (save_prefix,<EOL>'<STR_LIT>', save_format), format=save_format, dpi=<NUM_LIT>)<EOL><DEDENT>elif on_basemap:<EOL><INDENT>ax.draw(r)<EOL><DEDENT>texts = repel_text_from_axes(texts, ax, renderer=r, expand=expand_points)<EOL>history = [(np.inf, np.inf)]*<NUM_LIT:10><EOL>for i in xrange(lim):<EOL><INDENT>q1, q2 = [np.inf, np.inf], [np.inf, np.inf]<EOL>
Iteratively adjusts the locations of texts.

    Call adjust_text the very last, after all plotting (especially
    anything that can change the axes limits) has been done. This is
    because to move texts the function needs to use the dimensions of
    the axes, and without knowing the final size of the plots the
    results will be completely nonsensical, or suboptimal.

    First moves all texts that are outside the axes limits
    inside. Then in each iteration moves all texts away from each
    other and from points. In the end hides texts and substitutes them
    with annotations to link them to the respective points.

    Parameters
    ----------
    texts : list
        A list of :obj:`matplotlib.text.Text` objects to adjust.

    Other Parameters
    ----------------
    x : array_like
        x-coordinates of points to repel from; if not provided only uses text
        coordinates.
    y : array_like
        y-coordinates of points to repel from; if not provided only uses text
        coordinates
    add_objects : list or PathCollection
        a list of additional matplotlib objects to avoid; they must have a
        `.get_window_extent()` method; alternatively, a PathCollection or a
        list of Bbox objects.
    ax : matplotlib axe, default is current axe (plt.gca())
        axe object with the plot
    expand_text : array_like, default (1.05, 1.2)
        a tuple/list/... with 2 multipliers (x, y) by which to expand the
        bounding box of texts when repelling them from each other.
    expand_points : array_like, default (1.05, 1.2)
        a tuple/list/... with 2 multipliers (x, y) by which to expand the
        bounding box of texts when repelling them from points.
    expand_objects : array_like, default (1.05, 1.2)
        a tuple/list/... with 2 multipliers (x, y) by which to expand the
        bounding box of texts when repelling them from other objects.
    expand_align : array_like, default (1.05, 1.2)
        a tuple/list/... with 2 multipliers (x, y) by which to expand the
        bounding box of texts when autoaligning texts.
    autoalign: str or boolean {'xy', 'x', 'y', True, False}, default 'xy'
        Direction in wich the best alignement will be determined

        - 'xy' or True, best alignment of all texts determined in all
          directions automatically before running the iterative adjustment
          (overriding va and ha),
        - 'x', will only align horizontally,
        - 'y', will only align vertically,
        - False, do nothing (i.e. preserve va and ha)

    va : str, default 'center'
        vertical alignment of texts
    ha : str, default 'center'
        horizontal alignment of texts,
    force_text : tuple, default (0.1, 0.25)
        the repel force from texts is multiplied by this value
    force_points : tuple, default (0.2, 0.5)
        the repel force from points is multiplied by this value
    force_objects : float, default (0.1, 0.25)
        same as other forces, but for repelling additional objects
    lim : int, default 500
        limit of number of iterations
    precision : float, default 0.01
        iterate until the sum of all overlaps along both x and y are less than
        this amount, as a fraction of the total widths and heights,
        respectively. May need to increase for complicated situations.
    only_move : dict, default {'points':'xy', 'text':'xy', 'objects':'xy'}
        a dict to restrict movement of texts to only certain axes for certain
        types of overlaps.
        Valid keys are 'points', 'text', and 'objects'.
        Valid values are '', 'x', 'y', and 'xy'.
        For example, only_move={'points':'y', 'text':'xy', 'objects':'xy'}
        forbids moving texts along the x axis due to overlaps with points.
    avoid_text : bool, default True
        whether to repel texts from each other.
    avoid_points : bool, default True
        whether to repel texts from points. Can be helpful to switch off in
        extremely crowded plots.
    avoid_self : bool, default True
        whether to repel texts from its original positions.
    save_steps : bool, default False
        whether to save intermediate steps as images.
    save_prefix : str, default ''
        if `save_steps` is True, a path and/or prefix to the saved steps.
    save_format : str, default 'png'
        if `save_steps` is True, a format to save the steps into.
    add_step_numbers : bool, default True
        if `save_steps` is True, whether to add step numbers as titles to the
        images of saving steps.
    on_basemap : bool, default False
        whether your plot uses the basemap library, stops labels going over the
        edge of the map.
    args and kwargs :
        any arguments will be fed into obj:`ax.annotate` after all the
        optimization is done just for plotting the connecting arrows if
        required.

    Return
    ------
    int
        Number of iteration