Bonjour tout le monde,

je suis entrain d'écrire un code qui affiche des figures à l'aide de matplotlib,
et je veux les enregistrer dans un dossier.
Mes figures sont des histogrammes.
Pour la première figure ça marche bien,
sauf pour enregistrer la deuxième, il superpose le premier histogramme avec le deuxième histogramme et ainsi de suite ...
alors que j'aime bien voir chaque histogramme seul.

Voici mon code et j'espère que vous pouvez m'aider

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
import os # saving files
import matplotlib.pyplot as plt # plot and visualizing data 
 
## create directory for results
result_dir = 'DATA/'
directory = result_dir
if not os.path.exists(directory):
    os.makedirs(directory)
ax = plt.subplot()
rects = ax.bar(distance_z[0], population[0], width =0.5, color = 'b', align = 'center', alpha =1)
plt.xlabel('distance')
ax.set_title('data1')
plt.savefig(result_dir + 'my-data1'+ '.pdf', transparent=True, bbox_inches='tight')
 
ax = plt.subplot()
rects = ax.bar(distance_z[1], population[1], width =0.5, color = 'r', align = 'center', alpha =1)
plt.xlabel('distance')
ax.set_title('data2')
plt.savefig(result_dir + 'my-data2'+ '.pdf', transparent=True, bbox_inches='tight')
 
ax = plt.subplot()
rects = ax.bar(distance_z[3], population[3], width =0.5, color = 'g', align = 'center', alpha =1)
plt.xlabel('distance')
ax.set_title('data3')
plt.savefig(result_dir + 'my-data3'+ '.pdf', transparent=True, bbox_inches='tight')
Merci