python - Running median of y-values over a range of x -


Below is a scattering plot that I have made with two oval arrays.

Scatter plot example Enter image details here

d Want to add to this plot a moving average of y I have photoshop in an example:

Modified scatter plot image here Enter details

Specifically, let me know the two values F x axis with 1 need mid-point data in the unit compartment (this range will vary among the many plots, but I can do it manually adjusted). I appreciate any suggestions that can tell me in the right direction.

I will use for bin sorting for you. This way you can easily apply any function and set the category that you are interested in. Import as imported pilab plt n = 2000 total_bins = 10 # sample data x = np.random random (size = n) * 10 y = x ** 2 + np. Random.random (size = n) * x * 10 bins = np.linspace (X.min (), x max (), total_bins) delta = bins [1] -bins [0] idx = np.digitize (x, Cans) Running_media = [NP. Kt (total_bins)] in the category for the media (y [idx == k]) plt.scatter (x, y, color = 'k', alpha = .2, s = 2) plt.plot (bins-delta / 2, running_midian, 'r -', lw = 4, alpha = .8) plt.axis ('tight') Plt.show ()

 Enter image details here

As an example of the versatility of the method, the error bar given by standard deviation of each bin To add:

  running_std = [y [idx == k] for the .std () category (total_bins)] plt.errorbar (cartons -Delta / 2, running_media, running_stadi, fmt = none)   

here Enter image details

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -