1
$\begingroup$

I have some data with some margin of error and am using numpy arrays to plot that data. Assuming the precision is, let's say, 0.05 or 0.03grams, then the data will be something like

[4.0 $\pm$ 0.05, 3.05 $\pm$ 0.03]

How can I show this on my plot (either on the x axis or the y axis. If it's both, even better)?

I use pyplot and my OS is macOS

$\endgroup$
  • 1
    $\begingroup$ Can you use error bars? See the documentation and this example. Welcome to the site! $\endgroup$ – Emre Oct 25 '17 at 23:37
  • $\begingroup$ Thanks! Yeah, I think this pretty much solves my question, as simple as it seems. Should I answer to my own question? (I just read your profile) $\endgroup$ – evaristegd Oct 25 '17 at 23:57
  • $\begingroup$ Yes, please. Try to make it self-contained, so users don't need to follow links (unlike my comment). $\endgroup$ – Emre Oct 26 '17 at 0:03
  • $\begingroup$ It was just downvoted, so I think I'll just delete it. It was a very easy question anyways $\endgroup$ – evaristegd Oct 26 '17 at 0:08
  • 1
    $\begingroup$ @EvaristeGD Or you can answer your own question and mark the answer correct ... so that it might come useful for someone in the future. $\endgroup$ – Kiritee Gak Oct 26 '17 at 0:49
1
$\begingroup$

One can use the matplotlib.axes.Axes.errorbar class.

From this example in the documentation:

# example error bar values that vary with x-position
error = 0.1 + 0.2 * x

fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True)
ax0.errorbar(x, y, yerr=error, fmt='-o')
ax0.set_title('variable, symmetric error')

Acknowledgments: Thanks to Emre!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.