Plot ln(x) or logarithmic function on scatterplot in Matplotlib

Viewed 26

I currently have a scatterplot created in Matplotlib and fitted a logarithmic line of best fit.

import matplotlib.pyplot as plt
import numpy as np
plt.scatter(x=xData, y=yData)

fit = np.polyfit(np.log(xData), yData, 1)
The result was the function \
38.77 + 9.06*ln(x)

but I am having trouble graphing the actual function using matplotlib. How could I go about doing this? I have already plotted a regression line for the linear and exponential but haven't found a solution for this without using log-axes.

Current Example Scatter

EDIT:
As user t.o. mentioned in their comment, creating a linspace, plugging the x values in, and plotting the returned values works.

x = np.linspace(50, 250, 21)
y = 38.77 + 9.06*np.log(x)
plt.plot(x, y)
0 Answers
Related