Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 views
in Technique[技术] by (71.8m points)

matplotlib - Interpolate in one direction

I have sampled data and plot it with imshow():

enter image description here

I would like to interpolate just in horizontal axis so that I can easier distinguish samples and spot features. Is it possible to make interpolation just in one direction with MPL?


Update:
SciPy has whole package with various interpolation methods. I used simplest interp1d, as suggested by tcaswell:

def smooth_inter_fun(r):
    s = interpolate.interp1d(arange(len(r)), r)
    xnew = arange(0, len(r)-1, .1)
    return s(xnew)

new_data = np.vstack([smooth_inter_fun(r) for r in data])

Linear and cubic results:

enter image description here

enter image description here

As expected :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This tutorial covers a range of interpolation available in numpy/scipy. If you want to just one direction, I would work on each row independently and then re-assemble the results. You might also be interested is simply smoothing your data (exmple, Python Smooth Time Series Data, Using strides for an efficient moving average filter).

def smooth_inter_fun(r):
    #what ever process you want to use
new_data = np.vstack([smooth_inter_fun(r) for r in data])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...