Visualisation en Python

Introduction à Python pour la finance

Adina Howe

Professor

Matplotlib : une trousse de visualisation

Parcourez plus d'exemples de la galerie Matplotlib en cliquant sur ce lien.

matplotlib

Introduction à Python pour la finance

matplotlib.pyplot - fonctions de traçage variées

import matplotlib.pyplot as plt
Introduction à Python pour la finance

matplotlib.pyplot - fonctions de traçage variées

  • plt.plot()

    • prend des arguments décrivant les données à tracer
  • plt.show()

    • affiche le graphique à l'écran
Introduction à Python pour la finance

Tracer avec pyplot

import matplotlib.pyplot as plt
plt.plot(months, prices)
plt.show()
Introduction à Python pour la finance

Résultat du tracé

Graphique simple 2

Introduction à Python pour la finance

Ligne rouge pleine

import matplotlib.pyplot as plt
plt.plot(months, prices, color = 'red')
plt.show()
Introduction à Python pour la finance

Résultat du tracé

lignerouge

Introduction à Python pour la finance

Ligne en tirets

import matplotlib.pyplot as plt
plt.plot(months, prices, color = 'red', linestyle = '--')
plt.show()
Introduction à Python pour la finance

Résultat du tracé

tirets

Introduction à Python pour la finance

Couleurs et styles de ligne

couleur
'green' vert
'red' rouge
'cyan' cyan
'blue' bleu
style de ligne
'-' pleine
'--' en tirets
'-.' tirets-point
':' pointillée

Plus de détails sur les couleurs et lignes se trouvent ici.

Introduction à Python pour la finance

Ajouter des étiquettes et un titre

import matplotlib.pyplot as plt
plt.plot(months, prices, color = 'red', linestyle = '--')

# Add labels
plt.xlabel('Months')
plt.ylabel('Consumer Price Indexes, $')
plt.title('Average Monthly Consumer Price Indexes')

# Show plot
plt.show()
Introduction à Python pour la finance

Résultat du tracé

graphique_étiqueté

Introduction à Python pour la finance

Ajouter d'autres lignes

import matplotlib.pyplot as plt
plt.plot(months, prices, color = 'red', linestyle = '--')

# adding an additional line
plt.plot(months, prices_new, color = 'green', linestyle = '--') 

plt.xlabel('Months')
plt.ylabel('Consumer Price Indexes, $')
plt.title('Average Monthly Consumer Price Indexes')
plt.show()
Introduction à Python pour la finance

Résultat du tracé

deuxlignes

Introduction à Python pour la finance

Nuages de points

import matplotlib.pyplot as plt
plt.scatter(x = months, y = prices, color = 'red')
plt.show()
Introduction à Python pour la finance

Résultat du nuage de points

nuagedepoints

Introduction à Python pour la finance

Passons à la pratique !

Introduction à Python pour la finance

Preparing Video For Download...