Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to plot a line in python with an interval at each data point

Using python: I have a sequence of data points with means and a list with the standard deviation for each mean. I would like to plot the means as points connected by a solid line and the standard deviation as an halo around the line using the same color, but changed opacity and the width of the halo as an indication of the size of std. There is one plot which looks exactly like this: the time series plot in Seaborn and the Continuous Error Bars in Plotly: but the data model in the first is not suitable for my data as far as I can see and the output solution of the second is suboptimal for me. I haven't found a simple solution in Matplotlib. Obviously I could solve this by plotting the data points as lines from point to point and the std as a series of tetragons with different opacity. But maybe there is a more comfortable solution out there. Thanks in advance!

ps: my data looks like this:

means = [3, 5, 1, 8, 4, 6]

stds = [1.3, 2.6, 0.78, 3.01, 2.32, 2.9]

like image 538
fotis j Avatar asked Feb 27 '16 13:02

fotis j


Video Answer


1 Answers

Just do :

plt.plot (means)
plt.fill_between(range(6),means-stds,means+stds,alpha=.1)

For

enter image description here

like image 70
B. M. Avatar answered Oct 07 '22 21:10

B. M.