OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Average of Sampled Data at Different Sampling Points

  • Thread starter Thread starter Isotope
  • Start date Start date
I

Isotope

Guest
I need to plot the average of different trails of my sampled data y. The difficult part is that the corresponding sample points x do not coincide. However, x can only range from 0 to 1.

The following minimal reproducable example

Code:
import matplotlib.pyplot as plt

x1 = [0.1, 0.2, 0.4, 0.6, 0.75, 0.9]
x2 = [0, 0.14, 0.53, 0.6, 0.81, 0.9, 0.98]

y1 = [1, 4, 6, 5, 5, 3]
y2 = [3, 4, 7, 9, 7, 4, 2]

plt.plot(x1, y1, marker='o')
plt.plot(x2, y2, marker='x')
plt.grid()
plt.xlabel('x')
plt.ylabel('y')
plt.show()

produces this plot.

What is the nicest, and most pythonic way to do that? Is there any better solution opposed to linearly interpolate the data in order to create an x scale that coincides?

enter image description here
<p>I need to plot the average of different trails of my sampled data <code>y</code>. The difficult part is that the corresponding sample points <code>x</code> do not coincide. However, <code>x</code> can only range from 0 to 1.</p>
<p>The following minimal reproducable example</p>
<pre><code>import matplotlib.pyplot as plt

x1 = [0.1, 0.2, 0.4, 0.6, 0.75, 0.9]
x2 = [0, 0.14, 0.53, 0.6, 0.81, 0.9, 0.98]

y1 = [1, 4, 6, 5, 5, 3]
y2 = [3, 4, 7, 9, 7, 4, 2]

plt.plot(x1, y1, marker='o')
plt.plot(x2, y2, marker='x')
plt.grid()
plt.xlabel('x')
plt.ylabel('y')
plt.show()
</code></pre>
<p>produces this plot.</p>
<p>What is the nicest, and most pythonic way to do that?
Is there any better solution opposed to linearly interpolate the data in order to create an <code>x</code> scale that coincides?</p>
<p><a href="https://i.sstatic.net/TMW2cjYJ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/TMW2cjYJ.png" alt="enter image description here" /></a></p>
 

Latest posts

Top