Home > Software engineering >  increase accuracy of diagram
increase accuracy of diagram

Time:07-01

I am using the code below to use matplotlib to plot a diagram for a huge number of data.

def plot_en(filename):

   data_1 = np.loadtxt(f"{filename[0]}.en")
   data_2 = np.loadtxt(f"{filename[1]}.en")
   fig, (ax1, ax2) = plt.subplots(1, 2)
   plt.subplots_adjust(top = 1, bottom = 0.08, left = 1.5, right = 3.5, hspace = 0.25, wspace = 0.35)

   ax1.plot(data_1[:, 0], data_1[:, 1])
   ax2.plot(data_2[:, 0], data_2[:, 1])
plot_en(["forward1-on", "forward2-on"])

My diagram looks like this:

enter image description here

However, I need a more accurate diagram something like this:

enter image description here

Is there any way that I can make lines in my plot more distinguishable? or what change should i do on my code

CodePudding user response:

A simple solution is using moving average enter image description here

The one-line moving average calculation code is referenced from How to calculate rolling / moving average using python NumPy / SciPy?

You can search similar methods using keywords "noise", "smoothing", and others.

  • Related