Home > Enterprise >  Is there a way to stop plotting values after certain x value?
Is there a way to stop plotting values after certain x value?

Time:12-21

I'm using matplotlib for plotting results from training a Neural Network.

I successfully managed to plot my result using make_interp_spline on a given x-axis of 50 (Epochs).¹

Of course, x and y have the same size (both have 9 values), so it was easy for me to plot them. Now, I have to show multiple results on the same plot and so I need a different value on the x-axis, because certain results are based on a value (Epoch - which is my x-axis) > 50 (such as 60,70, etc..).

I tried to initialize a linspace > 50 and it works, but the results are going up in an exponential way.² Is there a way to "delete" points starting from x = 50?

Plus, if I add values in the x-axis, python throws me an error saying:

ValueError: Shapes of x (14,) and y (10,) are incompatible

I'm going to leave what I achieved until now.

import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import make_interp_spline

listA = [0.00,25.98386517667222,36.10066770794748,
         31.70895801412648,29.430944916297648,
         27.164039966977874,30.26995937742036,
         29.23696275469900,28.11570993620774,
         28.608378364299906]

epochList = [0, 10, 15, 20, 25, 30, 35, 40, 45, 50]

xnew = np.linspace(0, 50, 100)  
spl_A = make_interp_spline(epochList, listA, k=3)

plt.figure(figsize=(15,15))

plt.plot(xnew, spl_A(xnew), label='A')
plt.scatter(epochList,listA)

plt.xlabel('Epochs')
plt.xticks(np.arange(min(epochList), max(epochList) 1, 5.0))

plt.ylabel('MAE')
plt.yticks(np.arange(0, 62, 5.0))

del listA[0]
plt.scatter(epochList[listA.index(min(listA)) 1], min(listA), label=F'Best MAE = {min(listA)}', s=200, marker='*', c='black')
plt.legend(loc='upper right', prop={'size': 14})

plt.grid()
plt.show()

¹ ²

CodePudding user response:

You don't seem to be changing listA. From the second graph, it looks like it's plotting the old interolop function with new xnew. Since the old graph is exponential at the end, the new graph's end part becomes exponential. I am assuming you have new 'MAE' data for the later 'epoch'. So, you have to put those data in listA. The error you showed likely occurred from you adding new values to epoch list but not adding anything to listA.

  • Related