Using a single Quantity when plotting errorbars #2128
-
When creating a matplotlib plot with errorbars ( import numpy as np
from matplotlib import pyplot as plt
x = np.array([1, 2, 3])
y = np.array([3, 1.5, 1])
fig, ax = plt.subplots()
ax.errorbar(x, y, yerr=0.5)
plt.show() But this seem not to work when using pint: import numpy as np
import pint
from matplotlib import pyplot as plt
ureg = pint.UnitRegistry()
ureg.setup_matplotlib()
x = np.array([1, 2, 3]) * ureg.meter
y = np.array([3, 1.5, 1]) * ureg.second
fig, ax = plt.subplots()
ax.errorbar(x, y, yerr=ureg.Quantity(0.5, "second"))
plt.show() This outputs
Is this a pint issue or a matplotlib issue? Best regards! |
Beta Was this translation helpful? Give feedback.
Answered by
andrewgsavage
Feb 12, 2025
Replies: 1 comment 1 reply
-
it's a matplotlib one, |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
geolta
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's a matplotlib one,
np.asarray(x, dtype=object)
removes units hence the error message