def add_selection(self, pi):
<EOL>figure = pi.artist.figure<EOL>axes = pi.artist.axes<EOL>if axes.get_renderer_cache() is None:<EOL><INDENT>figure.canvas.draw()  <EOL><DEDENT>renderer = pi.artist.axes.get_renderer_cache()<EOL>ann = pi.artist.axes.annotate(<EOL>_pick_info.get_ann_text(*pi), xy=pi.target,<EOL>xytext=(np.nan, np.nan),<EOL>ha=_MarkedStr("<STR_LIT>"), va=_MarkedStr("<STR_LIT>"),<EOL>visible=self.visible,<EOL>**self.annotation_kwargs)<EOL>ann.draggable(use_blit=not self._multiple)<EOL>extras = []<EOL>if self._highlight:<EOL><INDENT>hl = self.add_highlight(*pi)<EOL>if hl:<EOL><INDENT>extras.append(hl)<EOL><DEDENT><DEDENT>sel = pi._replace(annotation=ann, extras=extras)<EOL>self._selections.append(sel)<EOL>for cb in self._callbacks["<STR_LIT>"]:<EOL><INDENT>cb(sel)<EOL><DEDENT>if ann.axes and ann.xyann == (np.nan, np.nan):<EOL><INDENT>fig_bbox = figure.get_window_extent()<EOL>ax_bbox = axes.get_window_extent()<EOL>overlaps = []<EOL>for idx, annotation_position in enumerate(<EOL>self.annotation_positions):<EOL><INDENT>ann.set(**annotation_position)<EOL>ann.update_positions(renderer)<EOL>bbox = ann.get_window_extent(renderer)<EOL>overlaps.append(<EOL>(_get_rounded_intersection_area(fig_bbox, bbox),<EOL>_get_rounded_intersection_area(ax_bbox, bbox),<EOL>idx == self._last_auto_position))<EOL><DEDENT>auto_position = max(range(len(overlaps)), key=overlaps.__getitem__)<EOL>ann.set(**self.annotation_positions[auto_position])<EOL>self._last_auto_position = auto_position<EOL><DEDENT>else:<EOL><INDENT>if isinstance(ann.get_ha(), _MarkedStr):<EOL><INDENT>ann.set_ha({-<NUM_LIT:1>: "<STR_LIT:right>", <NUM_LIT:0>: "<STR_LIT>", <NUM_LIT:1>: "<STR_LIT:left>"}[<EOL>np.sign(np.nan_to_num(ann.xyann[<NUM_LIT:0>]))])<EOL><DEDENT>if isinstance(ann.get_va(), _MarkedStr):<EOL><INDENT>ann.set_va({-<NUM_LIT:1>: "<STR_LIT>", <NUM_LIT:0>: "<STR_LIT>", <NUM_LIT:1>: "<STR_LIT>"}[<EOL>np.sign(np.nan_to_num(ann.xyann[<NUM_LIT:1>]))])<EOL><DEDENT><DEDENT>if (extras<EOL>or len(self.selections) > <NUM_LIT:1> and not self._multiple<EOL>or not figure.canvas.supports_blit):<EOL><INDENT>figure.canvas.draw_idle()<EOL><DEDENT>elif ann.axes:<EOL><INDENT>figure.draw_artist(ann)<EOL>figure.canvas.blit(figure.bbox)<EOL><DEDENT>if not self._multiple:<EOL><INDENT>for sel in self.selections[:-<NUM_LIT:1>]:<EOL><INDENT>self.remove_selection(sel)<EOL><DEDENT><DEDENT>return sel<EOL>
Create an annotation for a `Selection` and register it.

Returns a new `Selection`, that has been registered by the `Cursor`,
with the added annotation set in the :attr:`annotation` field and, if
applicable, the highlighting artist in the :attr:`extras` field.

Emits the ``"add"`` event with the new `Selection` as argument.  When
the event is emitted, the position of the annotation is temporarily
set to ``(nan, nan)``; if this position is not explicitly set by a
callback, then a suitable position will be automatically computed.

Likewise, if the text alignment is not explicitly set but the position
is, then a suitable alignment will be automatically computed.