Seite 1 von 1

PyPlot Probleme: invalid literal

Verfasst: Samstag 5. November 2011, 14:48
von recnice
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ß

Re: PyPlot Probleme: invalid literal

Verfasst: Samstag 5. November 2011, 14:51
von cofi
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.

Re: PyPlot Probleme: invalid literal

Verfasst: Samstag 5. November 2011, 16:14
von recnice
Ja spitze, Fehler beseitigt!

Danke & Gruß