Note
Click here to download the full example code
This example demonstrates passing a custom converter to numpy.genfromtxt
to
extract dates from a CSV file.
Traceback (most recent call last):
File "/build/matplotlib-mO9dyQ/matplotlib-3.1.2/examples/misc/load_converter.py", line 1
==============
^
SyntaxError: invalid syntax
==============
Load converter
==============
This example demonstrates passing a custom converter to `numpy.genfromtxt` to
extract dates from a CSV file.
"""
import dateutil.parser
from matplotlib import cbook, dates
import matplotlib.pyplot as plt
import numpy as np
datafile = cbook.get_sample_data('msft.csv', asfileobj=False)
print('loading', datafile)
data = np.genfromtxt(
datafile, delimiter=',', names=True,
dtype=None, converters={0: dateutil.parser.parse})
fig, ax = plt.subplots()
ax.plot(data['Date'], data['High'], '-')
fig.autofmt_xdate()
plt.show()
Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery