matplotlib problem
Verfasst: Mittwoch 18. August 2010, 09:12
Hallo,
mir gefällt dieses Beispiel ( http://matplotlib.sourceforge.net/examp ... atter.html ), d.h. dass jeder Datenpunkt im Graphen markiert ist. Leider bekomme ich beim ausführen diese Fehlermeldung:
mit Matplotlib 0.99.1.2. Ein anders Problem ist, dass die Eingabedatei 'msft.csv' nicht Verfügbar ist.
Wie könnte man das Problem beheben oder gibt es ein anderes Beispiel wo die Datenpunkte im Graphen markiert sind und dass vielleicht die Eingabewerte in einer Datenstruktur sich befinden?
Viele Dank im Voraus.
mir gefällt dieses Beispiel ( http://matplotlib.sourceforge.net/examp ... atter.html ), d.h. dass jeder Datenpunkt im Graphen markiert ist. Leider bekomme ich beim ausführen diese Fehlermeldung:
Code: Alles auswählen
$ python date_index_formatter.py
Traceback (most recent call last):
File "date_index_formatter.py", line 16, in <module>
datafile = cbook.get_sample_data('msft.csv', asfileobj=False)
AttributeError: 'module' object has no attribute 'get_sample_data'
Code: Alles auswählen
$ cat date_index_formatter.py
"""
When plotting daily data, a frequent request is to plot the data
ignoring skips, eg no extra spaces for weekends. This is particularly
common in financial time series, when you may have data for M-F and
not Sat, Sun and you don't want gaps in the x axis. The approach is
to simply use the integer index for the xdata and a custom tick
Formatter to get the appropriate date string for a given index.
"""
import numpy
from matplotlib.mlab import csv2rec
from pylab import figure, show
import matplotlib.cbook as cbook
from matplotlib.ticker import Formatter
datafile = cbook.get_sample_data('msft.csv', asfileobj=False)
print 'loading', datafile
r = csv2rec(datafile)[-40:]
class MyFormatter(Formatter):
def __init__(self, dates, fmt='%Y-%m-%d'):
self.dates = dates
self.fmt = fmt
def __call__(self, x, pos=0):
'Return the label for time x at position pos'
ind = int(round(x))
if ind>=len(self.dates) or ind<0: return ''
return self.dates[ind].strftime(self.fmt)
formatter = MyFormatter(r.date)
fig = figure()
ax = fig.add_subplot(111)
ax.xaxis.set_major_formatter(formatter)
ax.plot(numpy.arange(len(r)), r.close, 'o-')
fig.autofmt_xdate()
show()
$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> from matplotlib.mlab import csv2rec
>>> from pylab import figure, show
>>> import matplotlib.cbook as cbook
>>> from matplotlib.ticker import Formatter
Viele Dank im Voraus.