0

I'm trying to draw a line through the data as seen here

Data set

but this is what I get when I run my plot function

line output

Below is the code I'm using to generate the data as well as the line. I'm not sure why this is producing a web of graphs rather than a single line through the data, so any help is greatly appreciated!

#function that plots graphs of specific width and height.

def plot_func(x, y, xlabel, ylabel, title):
    fig = plt.figure(figsize=(16, 8))
    #plt.scatter(x, y, alpha=1200/len(x), linewidths= 1)
    p = np.poly1d(np.polyfit(x, y, 4))
    plt.plot(x, p(x))
    fig.suptitle(title, fontsize=24)
    plt.xlabel(xlabel, fontsize=18)
    plt.ylabel(ylabel, fontsize=16)

    plt.show()

Preferably I would like to be able to draw a single line through the data

Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52

0 Answers0