Skip to content

Commit 6d161d6

Browse files
committed
Merge remote-tracking branch 'matplotlib/v1.5.x' into v2.x
Conflicts: doc/_templates/layout.html Edited text removed from 2.x version of website
2 parents beb08c8 + 8dd65c3 commit 6d161d6

File tree

4 files changed

+76
-63
lines changed

4 files changed

+76
-63
lines changed

lib/matplotlib/axes/_axes.py

+39-41
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
import matplotlib.cbook as cbook
1818
from matplotlib.cbook import (mplDeprecation, STEP_LOOKUP_MAP,
19-
iterable, is_string_like)
19+
iterable, is_string_like,
20+
safe_first_element)
2021
import matplotlib.collections as mcoll
2122
import matplotlib.colors as mcolors
2223
import matplotlib.contour as mcontour
@@ -2903,29 +2904,44 @@ def xywhere(xs, ys, mask):
29032904
if key in kwargs:
29042905
plot_kw[key] = kwargs[key]
29052906

2906-
if xerr is not None:
2907-
if (iterable(xerr) and len(xerr) == 2 and
2908-
iterable(xerr[0]) and iterable(xerr[1])):
2909-
# using list comps rather than arrays to preserve units
2910-
left = [thisx - thiserr for (thisx, thiserr)
2911-
in cbook.safezip(x, xerr[0])]
2912-
right = [thisx + thiserr for (thisx, thiserr)
2913-
in cbook.safezip(x, xerr[1])]
2914-
else:
2915-
# Check if xerr is scalar or symmetric. Asymmetric is handled
2916-
# above. This prevents Nx2 arrays from accidentally
2917-
# being accepted, when the user meant the 2xN transpose.
2918-
# special case for empty lists
2919-
if len(xerr) > 1 and not ((len(xerr) == len(x) and not (
2920-
iterable(xerr[0]) and len(xerr[0]) > 1))):
2921-
raise ValueError("xerr must be a scalar, the same "
2907+
def extract_err(err, data):
2908+
'''private function to compute error bars
2909+
2910+
Parameters
2911+
----------
2912+
err : iterable
2913+
xerr or yerr from errorbar
2914+
data : iterable
2915+
x or y from errorbar
2916+
'''
2917+
if (iterable(err) and len(err) == 2):
2918+
a, b = err
2919+
if iterable(a) and iterable(b):
2920+
# using list comps rather than arrays to preserve units
2921+
low = [thisx - thiserr for (thisx, thiserr)
2922+
in cbook.safezip(data, a)]
2923+
high = [thisx + thiserr for (thisx, thiserr)
2924+
in cbook.safezip(data, b)]
2925+
return low, high
2926+
# Check if xerr is scalar or symmetric. Asymmetric is handled
2927+
# above. This prevents Nx2 arrays from accidentally
2928+
# being accepted, when the user meant the 2xN transpose.
2929+
# special case for empty lists
2930+
if len(err) > 1:
2931+
fe = safe_first_element(err)
2932+
if not ((len(err) == len(data) and not (iterable(fe) and
2933+
len(fe) > 1))):
2934+
raise ValueError("err must be a scalar, the same "
29222935
"dimensions as x, or 2xN.")
2923-
# using list comps rather than arrays to preserve units
2924-
left = [thisx - thiserr for (thisx, thiserr)
2925-
in cbook.safezip(x, xerr)]
2926-
right = [thisx + thiserr for (thisx, thiserr)
2927-
in cbook.safezip(x, xerr)]
2936+
# using list comps rather than arrays to preserve units
2937+
low = [thisx - thiserr for (thisx, thiserr)
2938+
in cbook.safezip(data, err)]
2939+
high = [thisx + thiserr for (thisx, thiserr)
2940+
in cbook.safezip(data, err)]
2941+
return low, high
29282942

2943+
if xerr is not None:
2944+
left, right = extract_err(xerr, x)
29292945
# select points without upper/lower limits in x and
29302946
# draw normal errorbars for these points
29312947
noxlims = ~(xlolims | xuplims)
@@ -2970,25 +2986,7 @@ def xywhere(xs, ys, mask):
29702986
caplines.extend(self.plot(xup, yup, 'k|', **plot_kw))
29712987

29722988
if yerr is not None:
2973-
if (iterable(yerr) and len(yerr) == 2 and
2974-
iterable(yerr[0]) and iterable(yerr[1])):
2975-
# using list comps rather than arrays to preserve units
2976-
lower = [thisy - thiserr for (thisy, thiserr)
2977-
in cbook.safezip(y, yerr[0])]
2978-
upper = [thisy + thiserr for (thisy, thiserr)
2979-
in cbook.safezip(y, yerr[1])]
2980-
else:
2981-
# Check for scalar or symmetric, as in xerr.
2982-
if len(yerr) > 1 and not ((len(yerr) == len(y) and not (
2983-
iterable(yerr[0]) and len(yerr[0]) > 1))):
2984-
raise ValueError("yerr must be a scalar, the same "
2985-
"dimensions as y, or 2xN.")
2986-
# using list comps rather than arrays to preserve units
2987-
lower = [thisy - thiserr for (thisy, thiserr)
2988-
in cbook.safezip(y, yerr)]
2989-
upper = [thisy + thiserr for (thisy, thiserr)
2990-
in cbook.safezip(y, yerr)]
2991-
2989+
lower, upper = extract_err(yerr, y)
29922990
# select points without upper/lower limits in y and
29932991
# draw normal errorbars for these points
29942992
noylims = ~(lolims | uplims)

lib/matplotlib/mlab.py

+7-22
Original file line numberDiff line numberDiff line change
@@ -3185,35 +3185,20 @@ def get_type(item, atype=int):
31853185
return atype
31863186

31873187
def get_justify(colname, column, precision):
3188-
ntype = type(column[0])
3188+
ntype = column.dtype
31893189

3190-
if (ntype == np.str or ntype == np.str_ or ntype == np.string0 or
3191-
ntype == np.string_):
3192-
length = max(len(colname), column.itemsize)
3190+
if np.issubdtype(ntype, str) or np.issubdtype(ntype, bytes):
3191+
# The division below handles unicode stored in array, which could
3192+
# have 4 bytes per char
3193+
length = max(len(colname), column.itemsize // column[0].itemsize)
31933194
return 0, length+padding, "%s" # left justify
31943195

3195-
if (ntype == np.int or ntype == np.int16 or ntype == np.int32 or
3196-
ntype == np.int64 or ntype == np.int8 or ntype == np.int_):
3196+
if np.issubdtype(ntype, np.int):
31973197
length = max(len(colname),
31983198
np.max(list(map(len, list(map(str, column))))))
31993199
return 1, length+padding, "%d" # right justify
32003200

3201-
# JDH: my powerbook does not have np.float96 using np 1.3.0
3202-
"""
3203-
In [2]: np.__version__
3204-
Out[2]: '1.3.0.dev5948'
3205-
3206-
In [3]: !uname -a
3207-
Darwin Macintosh-5.local 9.4.0 Darwin Kernel Version 9.4.0: Mon Jun
3208-
9 19:30:53 PDT 2008; root:xnu-1228.5.20~1/RELEASE_I386 i386 i386
3209-
3210-
In [4]: np.float96
3211-
---------------------------------------------------------------------------
3212-
AttributeError Traceback (most recent call la
3213-
"""
3214-
if (ntype == np.float or ntype == np.float32 or ntype == np.float64 or
3215-
(hasattr(np, 'float96') and (ntype == np.float96)) or
3216-
ntype == np.float_):
3201+
if np.issubdtype(ntype, np.float):
32173202
fmt = "%." + str(precision) + "f"
32183203
length = max(
32193204
len(colname),

lib/matplotlib/tests/test_axes.py

+14
Original file line numberDiff line numberDiff line change
@@ -4339,6 +4339,20 @@ def test_pandas_indexing_dates():
43394339
ax.plot('dates', 'values', data=without_zero_index)
43404340

43414341

4342+
@cleanup
4343+
def test_pandas_errorbar_indexing():
4344+
try:
4345+
import pandas as pd
4346+
except ImportError:
4347+
raise SkipTest("Pandas not installed")
4348+
4349+
df = pd.DataFrame(np.random.uniform(size=(5, 4)),
4350+
columns=['x', 'y', 'xe', 'ye'],
4351+
index=[1, 2, 3, 4, 5])
4352+
fig, ax = plt.subplots()
4353+
ax.errorbar('x', 'y', xerr='xe', yerr='ye', data=df)
4354+
4355+
43424356
@cleanup
43434357
def test_pandas_indexing_hist():
43444358
try:

lib/matplotlib/tests/test_mlab.py

+16
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,22 @@ def test_csv2rec_yearfirst(self):
393393
assert_array_equal(array['a'].tolist(), expected)
394394

395395

396+
class rec2txt_testcase(CleanupTestCase):
397+
def test_csv2txt_basic(self):
398+
# str() calls around field names necessary b/c as of numpy 1.11
399+
# dtype doesn't like unicode names (caused by unicode_literals import)
400+
a = np.array([(1.0, 2, 'foo', 'bing'),
401+
(2.0, 3, 'bar', 'blah')],
402+
dtype=np.dtype([(str('x'), np.float32),
403+
(str('y'), np.int8),
404+
(str('s'), str, 3),
405+
(str('s2'), str, 4)]))
406+
truth = (' x y s s2\n'
407+
' 1.000 2 foo bing \n'
408+
' 2.000 3 bar blah ')
409+
assert_equal(mlab.rec2txt(a), truth)
410+
411+
396412
class window_testcase(CleanupTestCase):
397413
def setUp(self):
398414
np.random.seed(0)

0 commit comments

Comments
 (0)