【Python|matplotlib】简单作图:散点图,条形图,频数分布直方图

官网大法好:https://matplotlib.org/index.html

决策树(回归)结果作图的例子:http://scikit-learn.org/stable/auto_examples/tree/plot_tree_regression.html#sphx-glr-auto-examples-tree-plot-tree-regression-py

自己用到的:

import matplotlib.pyplot as plt
def draw(y,yy,title,path):   
    print(title)
    
    index = np.arange(0,len(y),1)
    
    plt.scatter(index,y,color='cornflowerblue',label='true')#点  
    plt.plot(index,yy,color='yellowgreen',label='predict')#折线
    
    plt.xlabel('index')
    plt.ylabel('cost')
    plt.title(title)#显示图标题
    plt.legend()#显示图例
    plt.savefig(path+title+'.png')
    plt.show()
    
    rate = []
    fig, ax = plt.subplots()
    for i in range(0,len(x)):
        rate.append((yy[i]-y[i])/y[i])
    rate.sort()
    plt.bar(index,rate)#条形图
    plt.title(title+' Error')
    plt.savefig(path+title+'_error.png')
    plt.show()
    
    plt.title(title+' Error hist')
    plt.hist(rate)#频数分布直方图
    plt.savefig(path+title+'_errorHist.png')
    plt.show()



你可能感兴趣的:(可视化,Python)