You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error when using quantities when plotting errorbars #8871
I am plotting something that requires the use of standard error. I would like to keep all my arrays as Quantities arrays (using astropy quantities in this case). However, when giving yerr an array with dimensions, an exception is thrown.
Code for reproduction
import astropy.units as u
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 10)
y = np.sin(x*np.pi)
yerr = np.random.rand(10)
x_sec = x*u.second
y_meter = y*u.meter
yerr_meter = yerr*u.meter
fig = plt.figure()
ax = fig.add_subplot(111)
ax.errorbar(x_sec, y_meter, yerr_meter)
fig.show()
Actual outcome
Expected outcome
It is expected that errorbar would plot the points with errorbars using quantity arrays the same as regular arrays. When yerr is taken out, the quantities plot fine. Simply using yerr_meter.value does not work, as this throws an exception related to subtracting two different quantities (y_meter and yerr). I would rather not have to call .value on all the arguments.
Activity
dstansby commentedon Feb 2, 2018
This will be fixed by a combination of astropy/astropy#7037 and #10206
dstansby commentedon Sep 25, 2018
Closing as fixed; this now works with Matplotlib >= 2.2, and Astropy 2.0.6 or Astropy 3.1 (not yet released)
vuillaut commentedon Nov 25, 2020
Hi
Is this really solved? Or did another issue appear?
I copied the proposed code of the first issue.
astropy v4.1
matplotlib v3.1.3
Output
Lachimax commentedon May 30, 2021
I have the same error as above, running matplotlib 3.3.4 and astropy 4.2.1.
jklymak commentedon May 30, 2021
Please try latest matplotlib. If this is still an issue please open a new issue. Thanks!
jklymak commentedon May 30, 2021
This works fine with 3.4.2 and astropy 4.3.dev, so I don't think there is anything to do here.