{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Simple Anchored Artists\n\nThis example illustrates the use of the anchored helper classes found in\n:mod:`matplotlib.offsetbox` and in :mod:`mpl_toolkits.axes_grid1`.\nAn implementation of a similar figure, but without use of the toolkit,\ncan be found in :doc:`/gallery/misc/anchored_artists`.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n\n\ndef draw_text(ax):\n    \"\"\"\n    Draw two text-boxes, anchored by different corners to the upper-left\n    corner of the figure.\n    \"\"\"\n    from matplotlib.offsetbox import AnchoredText\n    at = AnchoredText(\"Figure 1a\",\n                      loc='upper left', prop=dict(size=8), frameon=True,\n                      )\n    at.patch.set_boxstyle(\"round,pad=0.,rounding_size=0.2\")\n    ax.add_artist(at)\n\n    at2 = AnchoredText(\"Figure 1(b)\",\n                       loc='lower left', prop=dict(size=8), frameon=True,\n                       bbox_to_anchor=(0., 1.),\n                       bbox_transform=ax.transAxes\n                       )\n    at2.patch.set_boxstyle(\"round,pad=0.,rounding_size=0.2\")\n    ax.add_artist(at2)\n\n\ndef draw_circle(ax):\n    \"\"\"\n    Draw a circle in axis coordinates\n    \"\"\"\n    from matplotlib.patches import Circle\n    from mpl_toolkits.axes_grid1.anchored_artists import AnchoredDrawingArea\n    ada = AnchoredDrawingArea(20, 20, 0, 0,\n                              loc='upper right', pad=0., frameon=False)\n    p = Circle((10, 10), 10)\n    ada.da.add_artist(p)\n    ax.add_artist(ada)\n\n\ndef draw_sizebar(ax):\n    \"\"\"\n    Draw a horizontal bar with length of 0.1 in data coordinates,\n    with a fixed label underneath.\n    \"\"\"\n    from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar\n    asb = AnchoredSizeBar(ax.transData,\n                          0.1,\n                          r\"1$^{\\prime}$\",\n                          loc='lower center',\n                          pad=0.1, borderpad=0.5, sep=5,\n                          frameon=False)\n    ax.add_artist(asb)\n\n\nfig, ax = plt.subplots()\nax.set_aspect(1.)\n\ndraw_text(ax)\ndraw_circle(ax)\ndraw_sizebar(ax)\n\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.14.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}