PyPlot Probleme: invalid literal

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
recnice
User
Beiträge: 45
Registriert: Sonntag 20. März 2011, 12:10

Hallo,

ich möchte gerne mit pyplot einige Daten plotten.
Noch stehen in der zu plottenden Liste nur zwei Werte, die auch schon Probleme machen, hier die Liste:
  • ['8.96047e-07,', '8.87331e-07,']
Also Fehlermeldung kommt:
Traceback (most recent call last):
File "simpleFoam_residual_plot.py", line 110, in <module>
plt.plot(x_p,y_p)
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2141, in plot
ret = ax.plot(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 3433, in plot
self.add_line(line)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 1385, in add_line
self._update_line_limits(line)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 1393, in _update_line_limits
p = line.get_path()
File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 651, in get_path
self.recache()
File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 439, in recache
y = np.asarray(self.convert_yunits(self._yorig), float)
File "/usr/lib/pymodules/python2.7/numpy/core/numeric.py", line 284, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: invalid literal for float(): 8.96047e-07,
pyplot scheint wohl mit der Darstellung der Zahlen nicht zurechtzukommen.
Weiß jemand wie ich die Zahlen umformatieren kann?

Gruß
Benutzeravatar
cofi
Python-Forum Veteran
Beiträge: 4432
Registriert: Sonntag 30. März 2008, 04:16
Wohnort: RGFybXN0YWR0

Das ist kein PyPy Problem, sondern deine Daten sind kaputt:

Code: Alles auswählen

#so sollten sie aussehen
In [2]: float('8.96047e-07')
Out[2]: 8.96047e-07
#so sehen sie aus
In [3]: float('8.96047e-07,')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/home/cofi/<ipython console> in <module>()

ValueError: invalid literal for float(): 8.96047e-07,
Mit anderen Worten: Du musst das Komma am Ende loswerden.
recnice
User
Beiträge: 45
Registriert: Sonntag 20. März 2011, 12:10

Ja spitze, Fehler beseitigt!

Danke & Gruß
Antworten