Matplotlib animate fill_between shape

后端 未结 5 2108
别那么骄傲
别那么骄傲 2021-01-04 02:48

I am trying to animate a fill_between shape inside matplotlib and I don\'t know how to update the data of the PolyCollection. Take this simple example: I have two lines and

5条回答
  •  我在风中等你
    2021-01-04 03:06

    Ok, as someone pointed out, we are dealing with a collection here, so we will have to delete and redraw. So somewhere in the update_data function, delete all collections associated with it:

    axes_dummy.collections.clear()
    

    and draw the new "fill_between" PolyCollection:

    axes_dummy.fill_between(x, y-sigma, y+sigma, facecolor='yellow', alpha=0.5)
    

    A similar trick is required to overlay an unfilled contour plot on top of a filled one, since an unfilled contour plot is a Collection as well (of lines I suppose?).

提交回复
热议问题