Skip to content
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

Build misc examples #6868

Merged
merged 11 commits into from
Aug 7, 2016
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
('axes_grid', 'axes_grid toolkit'),
('units', 'units'),
('widgets', 'widgets'),
('misc', 'Miscellaneous examples'),
]


Expand Down
1 change: 1 addition & 0 deletions examples/misc/image_thumbnail.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- noplot -*-
"""
You can use matplotlib to generate thumbnails from existing images.
matplotlib natively supports PNG files on the input side, and other
Expand Down
10 changes: 5 additions & 5 deletions examples/misc/longshort.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
csv file, computing the daily returns, appending the results to the
record arrays, joining on date
"""
import urllib
from six.moves import urllib
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

# grab the price data off yahoo
u1 = urllib.urlretrieve('http://ichart.finance.yahoo.com/table.csv?s=AAPL&d=9&e=14&f=2008&g=d&a=8&b=7&c=1984&ignore=.csv')
u2 = urllib.urlretrieve('http://ichart.finance.yahoo.com/table.csv?s=GOOG&d=9&e=14&f=2008&g=d&a=8&b=7&c=1984&ignore=.csv')
u1 = urllib.request.urlretrieve('http://ichart.finance.yahoo.com/table.csv?s=AAPL&d=9&e=14&f=2008&g=d&a=8&b=7&c=1984&ignore=.csv')
u2 = urllib.request.urlretrieve('http://ichart.finance.yahoo.com/table.csv?s=GOOG&d=9&e=14&f=2008&g=d&a=8&b=7&c=1984&ignore=.csv')

# load the CSV files into record arrays
r1 = mlab.csv2rec(file(u1[0]))
r2 = mlab.csv2rec(file(u2[0]))
r1 = mlab.csv2rec(open(u1[0]))
r2 = mlab.csv2rec(open(u2[0]))

# compute the daily returns and add these columns to the arrays
gains1 = np.zeros_like(r1.adj_close)
Expand Down
1 change: 1 addition & 0 deletions examples/misc/multiprocess.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- noplot -*-
# Demo of using multiprocessing for generating data in one process and plotting
# in another.
# Written by Robert Cimrman
Expand Down
1 change: 1 addition & 0 deletions examples/misc/rc_traits.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- noplot -*-
# Here is some example code showing how to define some representative
# rc properties and construct a matplotlib artist using traits.
# matplotlib does not ship with enthought.traits, so you will need to
Expand Down
14 changes: 9 additions & 5 deletions lib/matplotlib/mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -2387,8 +2387,10 @@ def rec_append_fields(rec, names, arrs, dtypes=None):
dtypes = dtypes * len(arrs)
else:
raise ValueError("dtypes must be None, a single dtype or a list")

newdtype = np.dtype(rec.dtype.descr + list(zip(names, dtypes)))
old_dtypes = rec.dtype.descr
if six.PY2:
old_dtypes = [(name.encode('utf-8'), dt) for name, dt in old_dtypes]
newdtype = np.dtype(old_dtypes + list(zip(names, dtypes)))
newrec = np.recarray(rec.shape, dtype=newdtype)
for field in rec.dtype.fields:
newrec[field] = rec[field]
Expand Down Expand Up @@ -2596,8 +2598,10 @@ def mapped_r2field(name):
if desc[0] not in key]
r2desc = [(mapped_r2field(desc[0]), desc[1]) for desc in r2.dtype.descr
if desc[0] not in key]
newdtype = np.dtype(keydesc + r1desc + r2desc)

all_dtypes = keydesc + r1desc + r2desc
if six.PY2:
all_dtypes = [(name.encode('utf-8'), dt) for name, dt in all_dtypes]
newdtype = np.dtype(all_dtypes)
newrec = np.recarray((common_len + left_len + right_len,), dtype=newdtype)

if defaults is not None:
Expand All @@ -2613,7 +2617,7 @@ def mapped_r2field(name):

if jointype != 'inner' and defaults is not None:
# fill in the defaults enmasse
newrec_fields = list(six.iterkeys(newrec.dtype.fields.keys))
newrec_fields = list(six.iterkeys(newrec.dtype.fields))
for k, v in six.iteritems(defaults):
if k in newrec_fields:
newrec[k] = v
Expand Down