Mis a jour le 2024-03-17, 13:3

Ajout de texte

Différents ajouts de texte sur un graphe ou une figure :
Principales propriétés pour modifier le texte dans ces différentes fonctions :
Exemple de graphes avec du texte : import math pyplot.suptitle('Titre de la figure', size = 'x-large') pyplot.subplot(211) pyplot.title('1er graphique') pyplot.scatter(range(5), [math.sqrt(x) for x in range(5)]) pyplot.text(0, 2, r'graphe de (x) = \sqrt{x}$', fontsize = 20, color = 'red', backgroundcolor = 'yellow') pyplot.subplot(212) pyplot.title('2eme graphique') pyplot.hist([math.sqrt(x) for x in range(50)]) pyplot.text(1, 8, 'histogramme ....', style = 'italic', fontweight = 'bold', fontsize = 20, family = 'serif', rotation = 10) pyplot.xlabel('valeurs des x') pyplot.figtext(0.1, 0.7, 'texte sur toute la figure', rotation = -45, fontsize = 30, color = 'orange', alpha = 0.5, fontweight = 'bold')
Annotations avec des flèches :
Systèmes de coordonnées :
Exemple : pyplot.suptitle('Titre de la figure', size = 'x-large') pyplot.subplot(211) pyplot.title('1er graphique') pyplot.scatter(range(5), [math.sqrt(x) for x in range(5)]) pyplot.annotate('1er point', xy = (0, 0), xytext = (1, 0), arrowprops = {'facecolor': 'yellow', 'edgecolor': 'red', 'width': 3, 'headwidth': 15, 'shrink': 0.2}, color = 'green', backgroundcolor = 'pink') pyplot.annotate('dernier point', xy = (4, 2), xytext = (2, 1), arrowprops = {'facecolor': 'cyan', 'edgecolor': 'cyan', 'width': 15, 'headwidth': 30, 'shrink': 0.1}) pyplot.subplot(212) pyplot.title('2eme graphique') pyplot.hist([math.sqrt(x) for x in range(50)]) pyplot.xlabel('valeurs des x') pyplot.annotate('valeur moyenne', xy = (4, 8), xytext = (0.7, 0.7), textcoords = 'figure fraction', arrowprops = {'color': 'violet', 'width': 15, 'headwidth': 30, 'alpha': 0.3})
Pour modifier les propriétés de la police :
Pour rajouter une flèche : pyplot.arrow(startX, startY, lengthX, lengthY, head_width = 0.02, head_length = 0.01)

Copyright python-simple.com
programmer en python, tutoriel python, graphes en python, Aymeric Duclert