Bonjour,

Je suis débutant et autodidacte en programmation Python.

Je rencontre un problème d'affichage entre les deux méthodes suivantes : pandas.plot() et plt.subplots().

1 ) Pourquoi pandas.plot() n'affiche pas toutes les valeurs du DataFrame ?

2 ) Existe-t-il une autre méthode pour modifier le label de l'axe X ?

Nom : Bug.jpeg
Affichages : 159
Taille : 65,4 Ko

Voici les sources :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import matplotlib.pyplot as plt
import pandas as pd
 
"""
tensions=pd.read_excel('./Dataset/Tensions.xls',index_col='date',parse_dates=True)
tensions.drop('PLS',axis='columns', inplace=True)
tensions.index=tensions.index.strftime("%Y/%m/%d %H")
"""
 
tensions=pd.DataFrame({'SYS': {'2026/08/29 10': 16,
  '2026/08/29 17': 16,
  '2026/08/30 10': 15,
  '2026/08/30 17': 16,
  '2026/08/31 10': 17,
  '2026/09/01 10': 17,
  '2026/09/01 18': 17,
  '2026/09/02 10': 15,
  '2026/09/02 17': 20,
  '2026/09/03 10': 14},
 'DIA': {'2026/08/29 10': 8,
  '2026/08/29 17': 8,
  '2026/08/30 10': 9,
  '2026/08/30 17': 8,
  '2026/08/31 10': 9,
  '2026/09/01 10': 14,
  '2026/09/01 18': 9,
  '2026/09/02 10': 7,
  '2026/09/02 17': 9,
  '2026/09/03 10': 7}})
 
 
tensions.plot(fontsize=7,rot=90,grid='True',title='Figure 1')
 
fig, ax1 = plt.subplots()
ax1.plot(tensions.index,tensions['SYS'],label='SYS')
ax1.plot(tensions.index,tensions['DIA'],label='DIA')
 
plt.title('Figure 2')
plt.legend(fontsize=6)
plt.xticks(fontsize=7,rotation=90)
plt.grid(True)
Merci pour votre aide ou remarques.

Cordialement Marc.

Python 3.12.3 matplotlib 3.10.7 pandas 2.3.3