Description
Setup code:
from matplotlib import pyplot as plt
import numpy as np
plt.ion()
f, a = plt.subplots()
The following code works fine, as expected, with the inputs getting raveled:
a.errorbar(np.array([[1, 2, 3], [4, 5, 6]]), np.array([[1, 2, 3], [4, 5, 6]]), fmt='o')
The following works too:
a.errorbar(np.array([[1, 2, 3], [4, 5, 6]]), np.array([[1, 2, 3], [4, 5, 6]]), yerr=3, fmt='o')
The arrays get raveled when the unerlying Line2D
object is created (here). I would expect the following two to work as well, but it does not:
>>> a.errorbar(np.array([[1, 2, 3], [4, 5, 6]]), np.array([[1, 2, 3], [4, 5 , 6]]), yerr=[3]*6, fmt='o')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jfoxrabi/miniconda3/lib/python3.5/site-packages/matplotlib/__init__.py", line 1892, in inner
return func(ax, *args, **kwargs)
File "/home/jfoxrabi/miniconda3/lib/python3.5/site-packages/matplotlib/axes/_axes.py", line 3020, in errorbar
lower, upper = extract_err(yerr, y)
File "/home/jfoxrabi/miniconda3/lib/python3.5/site-packages/matplotlib/axes/_axes.py", line 2961, in extract_err
raise ValueError("err must be [ scalar | N, Nx1 "
ValueError: err must be [ scalar | N, Nx1 or 2xN array-like ]
The issue appears to be that the input array-likes are never raveled within errorbar
to avoid issues with units (there is a comment to that effect here).
Is there a way to extract the units and reinstate them properly so that the input could always be made into an array? This would then allow a comparison with N
being x.size
instead of len(x)
as is happening now.
Matplotlib 2.0.0 running with Python 3.5.2 under anaconda on a Red Hat 6.5 machine.
UPDATE
Based on #8139, here is another related case. The current docs claim that an (N,1)
array like should work. In fact, it only works for actual arrays, not array-likes:
>>> a.errorbar(*[[1, 2, 3, 4, 5, 6]]*2, yerr=np.array([[i] for i in range(6)]), fmt='o') # OK
>>> a.errorbar(*[[1, 2, 3, 4, 5, 6]]*2, yerr=[[i] for i in range(6)], fmt='o')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jfoxrabi/miniconda3/lib/python3.5/site-packages/matplotlib/__init__.py", line 1892, in inner
return func(ax, *args, **kwargs)
File "/home/jfoxrabi/miniconda3/lib/python3.5/site-packages/matplotlib/axes/_axes.py", line 3020, in errorbar
lower, upper = extract_err(yerr, y)
File "/home/jfoxrabi/miniconda3/lib/python3.5/site-packages/matplotlib/axes/_axes.py", line 2965, in extract_err
in cbook.safezip(data, err)]
File "/home/jfoxrabi/miniconda3/lib/python3.5/site-packages/matplotlib/axes/_axes.py", line 2964, in <listcomp>
low = [thisx - thiserr for (thisx, thiserr)
TypeError: unsupported operand type(s) for -: 'int' and 'list'