You are reading an old version of the documentation (v3.1.3). For the latest version see https://matplotlib.org/stable/
Version 3.1.3
matplotlib
Fork me on GitHub

Related Topics

Load converterΒΆ

This example demonstrates passing a custom converter to numpy.genfromtxt to extract dates from a CSV file.

../../_images/sphx_glr_load_converter_001.png

Out:

loading /home/tcaswell/.virtualenvs/mpl313/lib/python3.8/site-packages/matplotlib/mpl-data/sample_data/msft.csv

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