{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Courbe représentative d'une fonction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Le minimum :" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from pylab import plt,linspace,show\n", "\n", "x = linspace(-3, 5, 50)\n", "y = x**2+3\n", "plt.plot(x, y)\n", "show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Mieux :" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from pylab import *\n", "x = linspace(-3, 5, 50)\n", "y = x**2+3\n", "plt.plot(x, y, label=\"f\")\n", "plt.legend()\n", "xlim(-3, 5)\n", "ylim(-1, 10)\n", "xlabel(\"abscisses\")\n", "ylabel(\"ordonnees\")\n", "title(\"TITRE\")\n", "show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Avec des axes se coupant en (0,0) et calcul de la meilleure fenêtre" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pylab import *\n", "\n", "x = linspace(-3, 5, 50)\n", "y1 = x**2-3\n", "y2= x**2 -2*x+2\n", "plt.plot(x, y1, label=\"f\")\n", "plt.plot(x, y2, \"r--\",label=\"g\")\n", "plt.legend()\n", "xlim(-3, 5)\n", "#ylim(-1, 10)\n", "xlabel(\"abscisses\")\n", "ylabel(\"ordonnees\")\n", "title(\"Fonctions du second degre\")\n", "plt.grid(True) #grille\n", "plt.setp(gca(),autoscale_on=True) #calcul de la meilleure fenêtre\n", "#pour avoir des axes se coupant en (0,0)\n", "ax = gca() #gca() retourne les axes courants\n", "ax.spines['right'].set_color('none')\n", "ax.spines['top'].set_color('none')\n", "ax.xaxis.set_ticks_position('bottom')\n", "ax.spines['bottom'].set_position(('data',0))\n", "ax.yaxis.set_ticks_position('left')\n", "ax.spines['left'].set_position(('data',0))\n", "\n", "show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plusieurs figures :\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pylab import *\n", "#definition d'une fonction du seconde degre f(x)=ax**2+bx+c\n", "def f(a,b,c,x):\n", " return a*x**2+b*x+c\n", "\n", "x = linspace(-5, 5, 50)\n", "y1 = f(1,2,-3,x)\n", "y2 = f(1,2,1,x)\n", "y3 = f(1,2,3,x)\n", "y4 = f(-1,-2,3,x)\n", "y5 = f(-1,-2,-1,x)\n", "y6 = f(-1,-2,-3,x)\n", "\n", "plt.subplot(231) #2 lignes , 3 colonnes 1ère figure\n", "plt.plot(x, y1, label=\"f1\")\n", "plt.legend()\n", "plt.grid(True)\n", "\n", "plt.subplot(232)\n", "plt.plot(x, y2, label=\"f2\")\n", "plt.legend()\n", "plt.grid(True)\n", "\n", "plt.subplot(233)\n", "plt.plot(x, y3, label=\"f3\")\n", "plt.legend()\n", "plt.grid(True)\n", "\n", "plt.subplot(234)\n", "plt.plot(x, y4, label=\"f4\")\n", "plt.legend()\n", "plt.grid(True)\n", "\n", "plt.subplot(235)\n", "plt.plot(x, y5, label=\"f5\")\n", "plt.legend()\n", "plt.grid(True)\n", "\n", "plt.subplot(236)\n", "plt.plot(x, y6, label=\"f6\")\n", "plt.legend()\n", "plt.grid(True)\n", "\n", "show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "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.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }