Add text to the Axes. Add the text *s* to the Axes at location *x*, *y* in data coordinates, with a default ``horizontalalignment`` on the ``left`` and ``verticalalignment`` at the ``baseline``. See :doc:`/gallery/text_labels_and_annotations/text_alignment`.
(self, x, y, s, fontdict=None, **kwargs)
| 651 | |
| 652 | @_docstring.interpd |
| 653 | def text(self, x, y, s, fontdict=None, **kwargs): |
| 654 | """ |
| 655 | Add text to the Axes. |
| 656 | |
| 657 | Add the text *s* to the Axes at location *x*, *y* in data coordinates, |
| 658 | with a default ``horizontalalignment`` on the ``left`` and |
| 659 | ``verticalalignment`` at the ``baseline``. See |
| 660 | :doc:`/gallery/text_labels_and_annotations/text_alignment`. |
| 661 | |
| 662 | Parameters |
| 663 | ---------- |
| 664 | x, y : float |
| 665 | The position to place the text. By default, this is in data |
| 666 | coordinates. The coordinate system can be changed using the |
| 667 | *transform* parameter. |
| 668 | |
| 669 | s : str |
| 670 | The text. |
| 671 | |
| 672 | fontdict : dict, default: None |
| 673 | |
| 674 | .. admonition:: Discouraged |
| 675 | |
| 676 | The use of *fontdict* is discouraged. Parameters should be passed as |
| 677 | individual keyword arguments or using dictionary-unpacking |
| 678 | ``text(..., **fontdict)``. |
| 679 | |
| 680 | A dictionary to override the default text properties. If fontdict |
| 681 | is None, the defaults are determined by `.rcParams`. |
| 682 | |
| 683 | Returns |
| 684 | ------- |
| 685 | `.Text` |
| 686 | The created `.Text` instance. |
| 687 | |
| 688 | Other Parameters |
| 689 | ---------------- |
| 690 | **kwargs : `~matplotlib.text.Text` properties. |
| 691 | Other miscellaneous text parameters. |
| 692 | |
| 693 | %(Text:kwdoc)s |
| 694 | |
| 695 | Examples |
| 696 | -------- |
| 697 | Individual keyword arguments can be used to override any given |
| 698 | parameter:: |
| 699 | |
| 700 | >>> text(x, y, s, fontsize=12) |
| 701 | |
| 702 | The default transform specifies that text is in data coords, |
| 703 | alternatively, you can specify text in axis coords ((0, 0) is |
| 704 | lower-left and (1, 1) is upper-right). The example below places |
| 705 | text in the center of the Axes:: |
| 706 | |
| 707 | >>> text(0.5, 0.5, 'matplotlib', horizontalalignment='center', |
| 708 | ... verticalalignment='center', transform=ax.transAxes) |
| 709 | |
| 710 | You can put a rectangular box around the text instance (e.g., to |