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

Scatter plot

Scatter plot (nuage de points) : x = [1, 2, 3, 4, 5] y1 = [1, 2, 3, 4, 5] y2 = [1, 4, 9, 16, 25] pyplot.scatter(x, y1, c = 'red') pyplot.scatter(x, y2, c = 'yellow')
Paramètres des scatter plots :
Exemple : x = [1, 2, 3, 4, 5] y1 = [1, 2, 3, 4, 5] y2 = [1, 4, 9, 16, 25] y3 = [25, 16, 9, 4, 1] pyplot.scatter(x, y1, s = 130, c = 'yellow', marker = '*', edgecolors = 'green') pyplot.scatter(x, y2, s = 50, c = 'red', marker = '+', linewidth = 3) pyplot.scatter(x, y3, s = 50, c = 'cyan', marker = 'o', edgecolors = 'none') pyplot.title('scatter plot')
Ajout d'une ligne dans un scatter plot :
Les paramètres c (pour la couleur) et s (pour la taille) peuvent être :
Exemple avec des paramètres variables : pyplot.scatter([0, 1, 2, 3, 4], [0, 2.4, 4.2, 5.6, 8.2], c = ['cyan', 'skyblue', 'blue', 'navy', 'black'], s = [110, 90, 70, 50, 30], marker = 'o', edgecolors = 'none') pyplot.plot([0, 4], [0, 8], color = 'red', linestyle = 'solid') pyplot.title('styles variables et droite')
Pour faire un scatter plot en coordonnées logarithmiques :
Pour introduire du jitter (bruit) dans un scatter plot, pour pouvoir mieux distinguer les points :
def jitter(values, amount):
    return values + numpy.random.normal(0, amount * (max(values) - min(values)), len(values))
  

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