Updating the positions and colors of pyplot.scatter

前端 未结 1 1202
礼貌的吻别
礼貌的吻别 2021-01-13 04:40

I have been struggling with this for a while and can\'t get it to work. I am reading a file in chunks and scatter plotting data from it, and I would like to \"animate\" it

相关标签:
1条回答
  • 2021-01-13 05:40

    The solution I found for this involves using Normalize to make a normalised colour list based on the relevant data, mapping it to a ScalarMappable, and using that to set the face colour and c limits on each frame of the animation. With scat the handle of the scatter plot and speedsList provides the colour data:

    n = mpl.colors.Normalize(vmin = min(speedsList), vmax = max(speedsList))
    m = mpl.cm.ScalarMappable(norm=n, cmap=mpl.cm.afmhot)
    scat.set_facecolor(m.to_rgba(speedsList))
    scat.set_clim(vmin=min(speedsList), vmax=max(speedsList))
    

    This does exactly what I expect it to.

    0 讨论(0)
提交回复
热议问题