{ "cells": [ { "cell_type": "markdown", "id": "cf5f72c3", "metadata": {}, "source": [ "# Matplotlib pour l'affichage de courbes" ] }, { "cell_type": "markdown", "id": "92233a49", "metadata": {}, "source": [ "**Matplotlib** est une bibliothèque permettant de gérer l'affichage de graphiques en tout genre.\n", "\n", "Pour pouvoir l'utiliser, il est nécessaire au préalable qu'elle soit installée :\n", "\n", "**pip install matplotlib**\n", "\n", "(uniquement sur votre propre machine en local)" ] }, { "cell_type": "markdown", "id": "bac6a4ea", "metadata": {}, "source": [ "Il faut ensuite importer **pyplot**, qui dépend de **matplotlib** par la commande suivante :" ] }, { "cell_type": "code", "execution_count": null, "id": "dd7b264f", "metadata": {}, "outputs": [], "source": [ "from matplotlib import pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "id": "349c69c5", "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "markdown", "id": "e1e489b4", "metadata": {}, "source": [ "La fonction de **pyplot** permettant d'afficher des graphiques est la fonction **plot**. Elle nécessite des vecteurs ou des matrices pour fonctionner." ] }, { "cell_type": "code", "execution_count": null, "id": "7f091189", "metadata": {}, "outputs": [], "source": [ "theta1 = np.linspace(0, 2*np.pi, 14)\n", "y1 = np.sin(theta1)\n", "theta2 = np.linspace(0, 2*np.pi, 101)\n", "y2 = np.sin(theta2)" ] }, { "cell_type": "markdown", "id": "9d1b0b20", "metadata": {}, "source": [ "Exemple de la fonction *sinus* prise sur l'intervale $[ 0 , 2\\pi ]$, dans deux cas différents :\n", "\n", "- 14 points sur la période\n", "- 101 points sur la période" ] }, { "cell_type": "code", "execution_count": null, "id": "7c6344dc", "metadata": {}, "outputs": [], "source": [ "plt.figure()\n", "plt.plot(theta1, y1, '*', label='14 points')\n", "plt.plot(theta2, y2, label='101 points')\n", "plt.xlabel(r'$\\theta$ (rd)')\n", "plt.ylabel(r'fonction $\\sin(\\theta)$')\n", "plt.legend()\n", "plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.16" } }, "nbformat": 4, "nbformat_minor": 5 }