{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "3cTtnEob7hrd" }, "source": [ "# matplotlib 入門 (15) nitta@tsuda.ac.jp\n", "\n", "# 15章: 図全体 (Figure) と座標系 (Axes) の関係を理解する\n", "\n", "figure を作成するのと同時に Axes を必要な個数だけ作成してしまう書き方を薦めるが、変わった Axes を作成したり、Axesを変わった配置にしたい場合は、まず figure() で、必要な大きさの Figure を作成する。\n", "\n", "
\n",
    "matplotlib.figure.Figure(*args, **kwargs)\n",
    "  [Parameters]\n",
    "    figsize=(6.4, 4.8) :  (width, height) dimension in inches\n",
    "    dpi=100 : dots per inch\n",
    "  [Returns]\n",
    "    Artist: the added artist\n",
    "
\n", "\n", "それから、figure.add_axes(rect=[left, bottom, width, height]) で好きな位置に Axes を配置していく。\n", "\n", "
\n",
    "matplotlib.figure.Figure.add_axes(self, *args, **kwargs)\n",
    "  [Parameters]\n",
    "    rect: [left, bottom, width, height]\n",
    "    projection: projection types \n",
    "    sharex, sharey: share x or y axis\n",
    "    label: label for the returned axes\n",
    "  [Returns]\n",
    "    axes\n",
    "
" ] }, { "cell_type": "markdown", "metadata": { "id": "4IJkWBhBEyKF" }, "source": [ "

\n", "下の実行例では、最初の Axes の追加では [left, bottom, width, height] = [0.1, 0.1, 0.8, 0.8]\n", "と指定しているので、図中の青の Axes の配置となる。\n", "\n", "2番目の Axes の追加では [left, bottom, width, height] = [0.6, 0.2, 0.4, 0.3] と指定しているので、図中の緑の Axes の配置となる。\n", "

\n", "\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "uA9qMNlH8QL1" }, "outputs": [], "source": [ "is_colab = 'google.colab' in str(get_ipython()) # for Google Colab" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 278 }, "executionInfo": { "elapsed": 1036, "status": "ok", "timestamp": 1652572735493, "user": { "displayName": "Yoshihisa Nitta", "userId": "15888006800030996813" }, "user_tz": -540 }, "id": "RmqkSqU47KvB", "outputId": "04a755ea-9c46-4e2a-bb4c-aa931ba8efe2" }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWgAAAEFCAYAAADOj31RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAWYUlEQVR4nO3df2wc5Z3H8c/3bNMuDYlbnPaSTcC0bg2BgBOWEkTpqRzBScQZhxYVWlHdgWRR4baoPR/kkHo9pDZco1ZUooJagkIrGrdKQxKFBBMgCFGFpBscyK/6kmtJk4UUQ+U2UDc/nO/94R+JYyf+MbM7M7vvl2TJO7M78x1IPjt5nmeex9xdAID4+YeoCwAAjIyABoCYIqABIKYIaACIKQIaAGKqPIqTVlVVeXV1dRSnBlDitm7d+o67T426jrGIJKCrq6uVzWajODWAEmdm+6KuYaxo4gCAmCKgASCmCGgAiCkCGgBiioAGgJgioAEgpgIPszOzD0p6SdIH+o+3wt3/K+hxAeB0VnXktKy9U29292h6ZUot9bVqnJOOuqzQhTEO+rCka939PTOrkPSyma1391dCODYADLGqI6clK7er52ivJCnX3aMlK7dLUtGFdOAmDu/zXv/Liv4fJpkGkBfL2jsHw3lAz9FeLWvvjKii/AmlDdrMysxsm6S3JW1w980jvKfJzLJmlu3q6grjtABK0JvdPePanmShBLS797p7naQZkj5tZpeM8J5Wd8+4e2bq1EQ8Bg8ghqZXpsa1PclCHcXh7t2SNkpaEOZxAWBAS32tUhVlQ7alKsrUUl8bUUX5EzigzWyqmVX2/56SNF/S74IeFwBG0jgnraU3zVa6MiWTlK5MaelNs4uug1AKZxTHNElPmFmZ+gL/V+6+NoTjAsCIGuekizKQTxU4oN39dUlzQqgFAHASniQEgJgioAEgpghoAIgpAhoAYoqABoCYIqABIKYIaACIKQIaAGKKgAaAmCKgASCmCGgAiCkCGgBiioAGgJgioAEgpsKYD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CSHpJ0jqQNZrbNzB6JuqAgzGyxmR2QdJWkp82sPeqaxqu/07ZZUrv6Op9+5e47o60qGDNbLmmTpFozO2Bmd0RdU0BXS7pN0rX9f2+2mdmiqIsKYJqkjWb2uvpuEDa4+9qIa8oLHvUGgJhK2h00AJQMAhoAYoqABoCYIqABIKYIaACIKQIaAGKKgAaAmPp/Ed7QVocTbjcAAAAASUVORK5CYII=\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "x = np.linspace(-2, 3, 10)\n", "y1 = x\n", "y2 = x ** 2\n", "\n", "fig = plt.figure(figsize=(5, 4))\n", "ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\n", "ax.scatter(x, y1)\n", "\n", "ax2 = fig.add_axes([0.6, 0.2, 0.4, 0.3])\n", "ax2.scatter(x, y2)\n", "\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "w6jsPKsK8Z0t" }, "outputs": [], "source": [] } ], "metadata": { "colab": { "authorship_tag": "ABX9TyNe9RmwBLfwdBHkYrzhaiIj", "collapsed_sections": [], "name": "matplotlib_tutorial_15.ipynb", "provenance": [] }, "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.6.13" } }, "nbformat": 4, "nbformat_minor": 1 }