Python 中 plt 画柱状图和折线图

1. 背景html

Python在一些数据可视化的过程当中须要使用 plt 函数画柱状图和折线图。python

 

2. 导入函数

import matplotlib.pyplot as plt

 

3. 柱状图post

array= np.array(array)

plt.hist(array, bins=50,facecolor="red", edgecolor="red" ,linewidth=5,alpha=0.7)

    plt.xlabel("")
    plt.ylabel("")
    plt.title("")

 

4.折线图spa

plt.figure(figsize=(num_group, 6))
X=[1,2,3,4,5,6,7,8,9]
Y=[1,2,3,4,5,6,7,8,9]#定义折线图的X,Y坐标

plt.plot(X, Y, label=str(model_name)) #折线图

for a, b in zip(X, Y):
    plt.text(a, b, '%.2f' % b, ha='center', va='bottom', fontsize=7)#每一个点的数值
plt.legend(loc=2)#显示每根折线的label
plt.title("{}".format(eval_key))#显示图名

 

5.保存code

print("=> saving {}".format(image_name))
plt.savefig(image_name)

  

 

转载于:https://www.cnblogs.com/siyuan1998/p/11373359.htmlorm