Colormap for errorbars in x-y scatter plot using matplotlib

前端 未结 4 1289
情书的邮戳
情书的邮戳 2020-12-06 05:28

I have a time series of data for which I have the quantity, y, and its error, yerr. I would now like to create a plot that shows y against phase (i.e. time / period % 1) wit

4条回答
  •  囚心锁ツ
    2020-12-06 06:00

    In addition to changing the color, another suggestion is to change the zorder of the error bars versus the scatter plot. This focuses the user on the data and draws out the general shape of the errors (which I think is your intention).

    from pylab import *
    
    # Generate some random data that looks like yours
    N = 1000
    X = random(N)
    Y = sin(X*5) + X*random(N)*.8
    Z = random(N)
    ERR = X*random(N)
    
    # These are the new arguments that I used
    scatter_kwargs = {"zorder":100}
    error_kwargs = {"lw":.5, "zorder":0}
    
    scatter(X,Y,c=Z,**scatter_kwargs)
    errorbar(X,Y,yerr=ERR,fmt=None, marker=None, mew=0,**error_kwargs )
    xlim(0,1)
    show()
    

    enter image description here

提交回复
热议问题