From ffeb9f229f191dfa78b628b2a0431aa90ea359b8 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Sat, 15 Aug 2015 19:52:18 -0400 Subject: [PATCH 1/3] MEP12 on load_converter.py --- examples/pylab_examples/load_converter.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/examples/pylab_examples/load_converter.py b/examples/pylab_examples/load_converter.py index 3d15fa6e3675..094abf57c095 100644 --- a/examples/pylab_examples/load_converter.py +++ b/examples/pylab_examples/load_converter.py @@ -1,9 +1,18 @@ from __future__ import print_function -from matplotlib.dates import bytespdate2num -#from matplotlib.mlab import load import numpy as np -from pylab import figure, show +import matplotlib.pyplot as plt import matplotlib.cbook as cbook +import matplotlib.dates as mdates + +# Note: matplotlib.dates doesn't have bytespdate2num. +# This function was copied off the internet. +# Source: http://pythonprogramming.net/colors-fills-matplotlib-tutorial/ +def bytespdate2num(fmt, encoding='utf-8'): + strconverter = mdates.strpdate2num(fmt) + def bytesconverter(b): + s = b.decode(encoding) + return strconverter(s) + return bytesconverter datafile = cbook.get_sample_data('msft.csv', asfileobj=False) print('loading', datafile) @@ -13,8 +22,8 @@ converters={0: bytespdate2num('%d-%b-%y')}, skiprows=1, usecols=(0, 2), unpack=True) -fig = figure() +fig = plt.figure() ax = fig.add_subplot(111) ax.plot_date(dates, closes, '-') fig.autofmt_xdate() -show() +plt.show() From 8e10d1b1ff91681fd9f12fcac3bb5049c3f545bf Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Sat, 15 Aug 2015 20:57:50 -0400 Subject: [PATCH 2/3] pep8 fixes --- examples/pylab_examples/load_converter.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/pylab_examples/load_converter.py b/examples/pylab_examples/load_converter.py index 094abf57c095..5b51ea3d6dce 100644 --- a/examples/pylab_examples/load_converter.py +++ b/examples/pylab_examples/load_converter.py @@ -4,11 +4,13 @@ import matplotlib.cbook as cbook import matplotlib.dates as mdates + # Note: matplotlib.dates doesn't have bytespdate2num. # This function was copied off the internet. # Source: http://pythonprogramming.net/colors-fills-matplotlib-tutorial/ def bytespdate2num(fmt, encoding='utf-8'): strconverter = mdates.strpdate2num(fmt) + def bytesconverter(b): s = b.decode(encoding) return strconverter(s) @@ -17,10 +19,9 @@ def bytesconverter(b): datafile = cbook.get_sample_data('msft.csv', asfileobj=False) print('loading', datafile) -dates, closes = np.loadtxt( - datafile, delimiter=',', - converters={0: bytespdate2num('%d-%b-%y')}, - skiprows=1, usecols=(0, 2), unpack=True) +dates, closes = np.loadtxt(datafile, delimiter=',', + converters={0: bytespdate2num('%d-%b-%y')}, + skiprows=1, usecols=(0, 2), unpack=True) fig = plt.figure() ax = fig.add_subplot(111) From 5c8efc9f3b4c74faba237c62420c5f362ec67549 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Sun, 16 Aug 2015 16:38:29 -0400 Subject: [PATCH 3/3] Removed custom bytespdate2num function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I’m going to take it on faith that this works. In the short period of time here, I wasn’t able to get it working on my local system. --- examples/pylab_examples/load_converter.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/examples/pylab_examples/load_converter.py b/examples/pylab_examples/load_converter.py index 5b51ea3d6dce..faf8f4d785e5 100644 --- a/examples/pylab_examples/load_converter.py +++ b/examples/pylab_examples/load_converter.py @@ -3,18 +3,7 @@ import matplotlib.pyplot as plt import matplotlib.cbook as cbook import matplotlib.dates as mdates - - -# Note: matplotlib.dates doesn't have bytespdate2num. -# This function was copied off the internet. -# Source: http://pythonprogramming.net/colors-fills-matplotlib-tutorial/ -def bytespdate2num(fmt, encoding='utf-8'): - strconverter = mdates.strpdate2num(fmt) - - def bytesconverter(b): - s = b.decode(encoding) - return strconverter(s) - return bytesconverter +from matplotlib.dates import bytespdate2num datafile = cbook.get_sample_data('msft.csv', asfileobj=False) print('loading', datafile)