0
下面是我的代碼片段,它根據給出的庫的順序繪製並創建趨勢線。我可以繪製線性,二次和其他多項式趨勢。但是,我無法爲可能符合log(n)或n log(n)趨勢的數據創建趨勢線。如何使用python繪製圖形?
任何命中如何去做這個?
import numpy as np
from matplotlib import pyplot, pylab
def plotChart(title, xlabel, ylabel,x,y,fit):
plot1 = pyplot.plot(x,y,"o",label="runtime")
plot2 = pyplot.plot(x,fit(x),"--", label="trendline")
pylab.title(title)
pylab.ylabel(ylabel)
pylab.xlabel(xlabel)
pyplot.legend()
pyplot.tight_layout()
pyplot.show()
def analyzeTimes(sampleList,timingList,order,title,xlabel,ylabel):
x = np.array(sampleList)
y = np.array(timingList)
coefficients = np.polyfit(x,y,order)
fit = np.poly1d(coefficients)
plotChart(
title + "\n %s"%(fit),
xlabel,
ylabel,
x,y,fit)