matplotlib.fill_between not working with mdates

时间:2016-04-25 09:19:00

标签: python datetime matplotlib

I want to create a plot like this: sample image

but in the x_axis I want to display the date. I have an array of datetime dates that I generate by cycling through different values for path_time:

           times.append(datetime.datetime.strptime(path_time,"%Y%m%d_%H%M%S"))

I can easily plot the scatter points like this:

for i in range(1,np.size(times)):

   plt.scatter(times[i],y[i],color='red')

To plot the errors, I generate the arrays y1 and y2 from the standard deviation of the data y and want to fill the area in between.

plt.fill_between(times,y1,y2,where=y>0.4,alpha=0.4,color='blue')

This works fine if the x axis is defined by integer vales but not if it's defined as dates which raises the error:

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

any advice how to solve this problem or work around it so that the error bar is plotted to the corresponding scatter point while still having the date on the x axis?

1 个答案:

答案 0 :(得分:0)

Mdates可以使用fill_between。问题是,在处理完日期之后,我遇到了一个对象。然后它不起作用。

如果x值的输入是日期列表,则可以正常工作。