3

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

theta
  • 24,593
  • 37
  • 119
  • 159
  • The answer to the question is technically, yes. What kind of interpolation are you interested in? What characteristics of the interpolation make you expect it to more easily distinguish features? – pelson Oct 31 '12 at 22:01
  • Any kind of interpolation across X-axis will make each of 22 samples more distinguished at least because: 1. horizontal borders will make samples more "individual" and 2. interpolating horizontally will make feature more easy to spot because vertical border will disappear, 3. it would provide new view. – theta Oct 31 '12 at 22:13

1 Answers1

4

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])
Community
  • 1
  • 1
tacaswell
  • 84,579
  • 22
  • 210
  • 199