I am trying to plot a fit for some data, but I keep getting the error:
ValueError: x and y must have same first dimension, but have shapes (5,) and (4,)
Interestingly the fits work fine when I don't include the final value in the arrays, so only using 4 instead of 5.
Any help to solve this will be greatly appreciated.
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
#normal fluid
x1 = np.array([7.41E+04,2.22E+05,1.11E+06,1.67E+06,2.22E+06])
y1 = np.array([5.15E+01,1.87E+02,1.70E+03,3.39E+03,3.49E+03])
#superfluid
x2 = np.array([7.41E+04,2.22E+05,1.11E+06,1.67E+06,2.22E+06])
y2 = np.array([7.63E+01,3.45E+02,2.32E+03,6.93E+03,6.83E+03])
logA1 = np.log(x1)
logB1 = np.log(y1)
m, c = np.polyfit(logA1, logB1, 1)
y_fit = np.exp(m*logA + c)
plt.plot(x1, y_fit, 'b--',label="Actual Data")
logA2 = np.log(x2)
logB2 = np.log(y2)
m, c = np.polyfit(logA2, logB2, 1)
y1_fit = np.exp(m*logA2 + c)
plt.plot(x2, y1_fit, 'r--',label="Predicted Data")
plt.scatter( x1 , y1, color='blue') #normal
plt.scatter( x2 , y2,color='red')#super
plt.xscale("log")
plt.yscale("log")
plt.ylabel('Δf/(√f*L)')
plt.xlabel('1/D')
plt.legend(loc='lower right')
plt.savefig('file.png', dpi = 500)
plt.show()