8000 MEP12 on load_converter.py · matplotlib/matplotlib@ffeb9f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit ffeb9f2

Browse files
committed
MEP12 on load_converter.py
1 parent 09f2577 commit ffeb9f2

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
from __future__ import print_function
2-
from matplotlib.dates import bytespdate2num
3-
#from matplotlib.mlab import load
42
import numpy as np
5-
from pylab import figure, show
3+
import matplotlib.pyplot as plt
64
import matplotlib.cbook as cbook
5+
import matplotlib.dates as mdates
6+
7+
# Note: matplotlib.dates doesn't have bytespdate2num.
8+
# This function was copied off the internet.
9+
# Source: http://pythonprogramming.net/colors-fills-matplotlib-tutorial/
10+
def bytespdate2num(fmt, encoding='utf-8'):
11+
strconverter = mdates.strpdate2num(fmt)
12+
def bytesconverter(b):
13+
s = b.decode(encoding)
14+
return strconverter(s)
15+
return bytesconverter
716

817
datafile = cbook.get_sample_data('msft.csv', asfileobj=False)
918
print('loading', datafile)
@@ -13,8 +22,8 @@
1322
converters={0: bytespdate2num('%d-%b-%y')},
1423
skiprows=1, usecols=(0, 2), unpack=True)
1524

16-
fig = figure()
25+
fig = plt.figure()
1726
ax = fig.add_subplot(111)
1827
ax.plot_date(dates, closes, '-')
1928
fig.autofmt_xdate()
20-
show()
29+
plt.show()

0 commit comments

Comments
 (0)
0