Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 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 Answer

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])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...