1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from math import *
import os#pour le chemin
from matplotlib import patches
import numpy as np
#-------------
nom="convexite_1.png" #!!! penser à changer ¡¡¡
#-------------
# paramètres à choisir
(L,l)=(4.5,3)#largeur, hauteur
xmin,xmax=-2,2
y0=0.3#centre vertical du repère
echelle=1#taille en cm de l'unite a l'ecran
pas=pi/10#tous les combien (en x comme en y) on met des vecteurs
eps_vecteur=0.25#longueur d'une fleche unitaire en carreaux.
# fonction
m=0.9
def f(x):
return(x**2/2+x**3/5+0.5)
# -----------------------------------
# modules
# quelques paramètres par défaut
plt.style.use('bmh') # pour la police des équations
plt.rcParams["font.size"] = 10
plt.rcParams['axes.facecolor'] = "white" # font blanc pour les graphiques (bmh met du gris)
# calcul automatique axe Y
rapport=L/l
demideltay=(xmax-xmin)/rapport/2
ymin,ymax=y0-demideltay,y0+demideltay
# définition de la figure + divers paramètres
alpha = echelle/9.5*(xmax-xmin)#valeur determinee empiriquement
Linch,linch=(L*alpha,l*alpha)
fig, lafigure = plt.subplots(figsize=(Linch,linch))
lafigure.set_visible
fig.tight_layout() # to nicely fit the subplot(s) in the figure
lafigure.axis([xmin,xmax,ymin,ymax]) # permet que si qqch dépasse ça ne perturbe rien
lafigure.grid(False)
#graduations automatiques
Lx=np.arange(int(xmin), int(xmax)+1, 1)
Ly=np.arange(int(ymin), int(ymax)+1, 1)
Lxmot=['' % x for x in Lx]
Lymot=['' % y for y in Ly]
plt.xticks(Lx, Lxmot)
plt.yticks(Ly, Lymot)
# axes
lafigure.plot([0,0],[ymin,ymax], color ='black', linewidth=0.5, linestyle="-")
lafigure.plot([xmin,xmax],[0,0], color ='black', linewidth=0.5, linestyle="-")
couleur="#005500"
(a,b)=(-1,1)
lafigure.plot([a,b],[f(a),f(b)], color =couleur, linewidth=0.25, linestyle="-")
# fonctions à tracer f(X)
ep=0.25
lacouleur='#AA44CC'
X1 = np.linspace(xmin,xmax, 256,endpoint=True)
Y1 = f(X1)
lafigure.plot(X1, Y1, color="black", linewidth=ep, linestyle="-")
def pointilles(x,y):
#trace les pointilles du point (x,y)
lafigure.plot([x,x], [y,0], color="black", linewidth=ep, linestyle="--")
lafigure.plot([x,0], [y,y], color="black", linewidth=ep, linestyle="--")
pointilles(a,f(a))
pointilles(b,f(b))
delta=0.0
lafigure.annotate(r'$a$',
xy=(a,-0.2),
ha='center', va='center',
#xytext=(echx, echy+0.3),
arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2"),
transform=fig.transFigure)
lafigure.annotate(r'$b$',
xy=(b,-0.2),
ha='center', va='center',
#xytext=(echx, echy+0.3),
arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2"),
transform=fig.transFigure)
# enregistrement
chemin=os.path.abspath(os.getcwd())#va enregistrer dans le dossier courant`
print(chemin+nom)
plt.savefig(chemin+"/"+nom, dpi=288)
plt.show() |
Partager