Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MEP12 on load_converter.py #4932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 17, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
MEP12 on load_converter.py
  • Loading branch information
ericmjl committed Aug 15, 2015
commit ffeb9f229f191dfa78b628b2a0431aa90ea359b8
19 changes: 14 additions & 5 deletions 19 examples/pylab_examples/load_converter.py
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about this. My version of Matplotlib definitely has bytespdate2num

And it is in the main repository here https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/dates.py#L308

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let me try conda installing the latest MPL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was added in February 0a24a56 so it wound be in any released version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very weird, I cannot make the import statements work, though. I get the error:

In [9]: import matplotlib.dates as mdate

In [10]: mdate.bytespdate2num()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-7c2709974f11> in <module>()
----> 1 mdate.bytespdate2num()

AttributeError: 'module' object has no attribute 'bytespdate2num'

Any idea what's going on? Is the import statement not done correctly?

# 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)
Expand All @@ -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()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.