Problème:
Comment spécifier des graduations en abscisses ou en ordonnées avec matplotlib?
Solution:
Utiliser matplotlib.pyplot.xticks pour les graduations des abscisses et matplotlib.pyplot.yticks pour les graduations en ordonnées.
Exemple:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Importations. | |
| import matplotlib.pyplot as plt | |
| # Valeurs pour l'exemple. | |
| x = [4, 1, 3, 5, 6] | |
| y = [2, 7, 2, 9, 5] | |
| # Tracé. | |
| plt.scatter(x, y) | |
| # Spécification des graduations. | |
| plt.xticks([0, 2, 4, 6, 8]) | |
| plt.yticks([0, 2, 4, 6, 8, 10]) | |
| # Affichage. | |
| plt.show() |

Laisser un commentaire