Visualisation en Python

Introduction à Python pour la finance

Adina Howe

Instructor

Matplotlib : Un package de visualisation

Pour découvrir davantage la galerie Matplotlib, cliquez sur ce lien.

matplotlib

Introduction à Python pour la finance

matplotlib.pyplot - diverses fonctions de graphiques

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

matplotlib.pyplot - diverses fonctions de graphiques

  • plt.plot()

    • accepte des arguments qui décrivent les données à représenter graphiquement
  • plt.show()

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

Graphique avec pyplot

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

Résultat du graphique

Simple plot2

Introduction à Python pour la finance

Ligne rouge continue

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

Résultat du graphique

redline

Introduction à Python pour la finance

Ligne pointillée

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

Résultat du graphique

dash

Introduction à Python pour la finance

Couleurs et styles de lignes

couleur
'vert vert
'rouge' rouge
'cyan' cyan
'bleu' bleu
style de ligne
'-' ligne continue
'--' ligne pointillée
'-.' ligne pointillée-point
':' pointillé

Vous trouverez davantage de documentation sur les couleurs et les lignes ici.

Introduction à Python pour la finance

Ajouter des étiquettes et des titres

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 graphique

labeled_plot

Introduction à Python pour la finance

Ajouter des lignes supplémentaires

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 graphique

twolines

Introduction à Python pour la finance

Diagrammes de dispersion

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

Résultat du diagramme en nuage de points

scatterplot

Introduction à Python pour la finance

Passons à la pratique !

Introduction à Python pour la finance

Preparing Video For Download...