4

I tried to plot error bar with Matplotlib like graphic attached, I can't made it, any suggestion?

import numpy as np
import matplotlib.pyplot as plt

Media   = data["Media"]
Periodo = data["Periodo"]
P10th     = data["P10th"]
P90th     = data["P90th"]
ind = np.arange(N)    # the x locations for the groups

width = 0.35       # the width of the bars: can also be len(x) sequence

fig, ax = plt.subplots()

ax.errorbar(Media, P90th, P10th, color='red', ls='--', marker='o', capsize=5, capthick=1, ecolor='black')
plt.xticks(ind, ('1910-1940', '1950-1990', '1990-2000', '2001-2010') )
ax.set_ylim(ylims)

I tried to plot with marplotlib this kind of graphic

here my data, please can you help me.

This is my output

enter image description here

5
  • I edited my question and put the code that I tried. Thanks Commented Jun 15, 2020 at 18:19
  • Do you need the line itself to be red and dotted? Commented Jun 15, 2020 at 19:02
  • What is the error / output you currently get? errorbar takes up to 4 positional arguments. You called the function as errorbar(x=Media, y=P90th, xerr=P10th) and left yerr blank (when you don't state the keyword explicity, they get unpacked in default order). Commented Jun 15, 2020 at 19:54
  • I don't got error, but basically I can't plot the percentiles 90 and 10 together. Commented Jun 15, 2020 at 21:20
  • In the table you provide, you have 4 data points, while in the plot you have 5. What's the actual data? Commented Jun 16, 2020 at 4:41

1 Answer 1

10

Here's the plot for your data:

p_10 = [.19,.62, .77, 1]
p_90 = [7.19, 6.67, 7.36, 8.25]
M = [1.16, 2.06, 2.17, 2.52]

fig = plt.figure()
x = [1, 2, 3, 4]
y = M
yerr = [p_10, # 'down' error
        p_90]  # 'up' error

plt.errorbar(x, y, yerr=yerr, capsize=3, fmt="r--o", ecolor = "black")

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.