For a class I am needing to make a lot of plots in a logarithmic space and get a line of best fit to find the slope. I seem to be getting correct values for the slope and intercept when I do it the way I show below, but the graph I produce shows the line of best fit as almost step-like instead of an actual smooth line. Here is the function I have been using to make the plots:
def scatterlinearfitlogscale(X, Y, xlab, ylab, title, color, colorline):
plt.scatter(X, Y, color=color)
plt.xscale('log')
plt.yscale('log')
plt.xlabel(xlab, fontsize='16')
plt.ylabel(ylab, fontsize='16')
plt.title(title, fontsize='20', fontweight='bold')
m, b = np.polyfit(X, Y, 1)
plt.plot(X, m*np.array(X)+b, linewidth=2, color=colorline)
plt.show()
This produces (when applied to a set of log'd data, in this case, rowing records, not super relevant): Graphs of rowing records X number of oarspeople
Does anyone know why the line is shown step-like that way? My biggest concern: am I making an error when having the line calculated, or is this due to how it is being displayed in a logarithmic space?
Thank you!
update: thank you so much! plotting it on a linear scale with the log'd values gave me the straight line I was looking for. I should have realized this sooner!