0
votes

I'm using pandas and Matplotlib to create plots. When trying to plot the error bars as shaded areas using matplotlib.pyplot.step, it looks like this kind of graphs don't have such option.

Below, I'm adding one of my plots as an example. The error bars are designed manually to illustrate the desired result.

Velocity plot

1
Please provide what you have tried so far, where you have gotten stuck, and the specific error you are encountering. That way, we can easily help you with your problem. - WangGang
If you add some runnable code together with some test data, you'll highly increase your chances of obtaining helpful answers. Even better if you add links to documentation and highly related posts. And maybe some approaches you tested that didn't work out as desired. - JohanC
You will have to use plt.fill_between to get the desired result. I suggest you read up on that function and look at posts about it here on SO. If you encounter a specific issue, please come back with the code that you've used and that reproduces the problem. - Diziet Asahi

1 Answers

0
votes

Thanks for the answer... i've tried already with plt.fill_between after the first post and it works very well.

Here you have the code.

Data:

Date = [1956-08-11, 1966-02-17, 1979-02-25, 1990-08-22, 1999-01-18, 2008-07-22, 2015-07-09, 2018-08-28]
Vel = [0.407244, 0.414471, 0.376604, 0.337854, 0.596332, 0.631590, 0.853729, 0.722059]
Error = [0.5, 0.4, 0.3, 0.3, 0.2, 0.2, 0.1, 0.1]

So the code for the plot is:

fig, ax = plt.subplots(figsize = (9, 6), constrained_layout=True)
ax.step(x=Date, y=Vel, color='k')
ax.fill_between(Date2, Vel_PT1-Errors, Vel_PT1+Errors, step='pre', color='k', alpha=0.15)
ax.set_title (f'Profile T1', fontsize=12, fontweight='bold')
ax1.set_xlabel('YEARS', fontsize=10)
ax.set_ylabel('Velocity (m)', fontsize=10, fontweight='bold')
ax.yaxis.grid(linestyle='--')
ax.xaxis.grid(linestyle='--')
plt.show()

Thank you very much guys