Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.lang.python > #3024
| From | marc@marc.marc |
|---|---|
| Newsgroups | fr.comp.lang.python |
| Subject | Re: Tracer une courbe à partir d'un fichier text |
| Date | 2018-01-22 13:41 +0100 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <p44m6i$1ngm$1@gioia.aioe.org> (permalink) |
| References | <2f5f9fc0-2db0-49f2-830c-b86bda4dd63c@googlegroups.com> |
Bonjour,
moyennant une petite modification du fichier texte ( ajout d'un # au
début de la première ligne ( X Y)):
import matplotlib.pyplot as plt
import numpy as np
data = np.loadtxt("Values.txt")
plt.plot(data[:,0],data[:,1],"ro")
plt.show()
devrait afficher la courbe
Pour utiliser le fichier tel quel ( sans le dièze ) il faut remplacer la
ligne ci dessus avec le loadtxt par :
f = open("Values.txt" , 'r')
f.readline() # lit la premiere ligne
data = np.loadtxt(f)
f.close()
Dans les deux cas data est un tableau numpy de 10 lignes et 2 colonnes.
La première colonne data[:,0] est x, data[:,1] la deuxième colonne est y.
Cordialement.
Marc
Le 20/01/2018 à 15:59, baladjy@gmail.com a écrit :
> Bonjour à tous,
>
> Je suis débutant sur python. Je souhaiterai savoir comment on fait pour tracer une courbe à partir d'un fichier text
>
> Voici les données dans le fichier text :
>
> X Y
> 0 47047.969
> 1 46959.758
> 2 46855.414
> 3 46701.742
> 4 46354.426
> 5 44898.340
> 6 36412.832
> 7 18628.641
> 8 7671.260
> 9 5338.369
> 10 4831.740
>
>
> voici le code que j'ai écris :
>
> import matplotlib.pyplot as plt
> import numpy as np
>
> f = open("Values.txt" , 'r')
> t = f.readlines()
> t.remove(t[0])
> list = []
> for i in t:
> list.append(i.split())
>
> for i in range(len(list)):
> value=list[i]
> #print(value)
> w =[]
> for i in range(len(value)):
> w = value[i]
> w = float(w)
> y = []
> y.append(w)
> print(y[:,0])
>
>
> Comment fait on pour créer une liste pour x et une autre liste pour y?
> et ensuite le tracer ?
>
> Merci,
> cordialement,
>
Back to fr.comp.lang.python | Previous | Next — Previous in thread | Find similar
Tracer une courbe à partir d'un fichier text baladjy@gmail.com - 2018-01-20 06:59 -0800
Re: Tracer une courbe à partir d'un fichier text Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2018-01-20 18:12 +0100
Re: Tracer une courbe à partir d'un fichier text baladjy@gmail.com - 2018-01-20 12:45 -0800
Re: Tracer une courbe à partir d'un fichier text yves <yves@free.invalid> - 2018-01-21 10:35 +0000
Re: Tracer une courbe à partir d'un fichier text yves <yves@free.invalid> - 2018-01-21 16:01 +0000
Re: Tracer une courbe à partir d'un fichier text marc@marc.marc - 2018-01-22 13:41 +0100
csiph-web