@@ -118,7 +118,15 @@ you will see that the x tick labels are all squashed together.
118
118
119
119
import matplotlib.cbook as cbook
120
120
datafile = cbook.get_sample_data('goog.npy')
121
- r = np.load(datafile).view(np.recarray)
121
+ try:
122
+ # Python3 cannot load python2 .npy files with datetime(object) arrays
123
+ # unless the encoding is set to bytes. Hovever this option was
124
+ # not added until numpy 1.10 so this example will only work with
125
+ # python 2 or with numpy 1.10 and later.
126
+ r = np.load(datafile, encoding='bytes').view(np.recarray)
127
+ except TypeError:
128
+ # Old Numpy
129
+ r = np.load(datafile).view(np.recarray)
122
130
plt.figure()
123
131
plt.plot(r.date, r.close)
124
132
plt.title('Default date handling can cause overlapping labels')
@@ -179,8 +187,14 @@ right.
179
187
180
188
# load up some sample financial data
181
189
datafile = cbook.get_sample_data('goog.npy')
182
- r = np.load(datafile).view(np.recarray)
183
-
190
+ try:
191
+ # Python3 cannot load python2 .npy files with datetime(object) arrays
192
+ # unless the encoding is set to bytes. Hovever this option was
193
+ # not added until numpy 1.10 so this example will only work with
194
+ # python 2 or with numpy 1.10 and later.
195
+ r = np.load(datafile, encoding='bytes').view(np.recarray)
196
+ except TypeError:
197
+ r = np.load(datafile).view(np.recarray)
184
198
# create two subplots with the shared x and y axes
185
199
fig, (ax1, ax2) = plt.subplots(1,2, sharex=True, sharey=True)
186
200
@@ -363,4 +377,3 @@ argument takes a dictionary with keys that are Patch properties.
363
377
# place a text box in upper left in axes coords
364
378
ax.text(0.05, 0.95, textstr, transform=ax.transAxes, fontsize=14,
365
379
verticalalignment='top', bbox=props)
366
-
0 commit comments