1、数据可视化呈现的最基础图形就是:柱状图、水平条形图、折线图等等;
import matplotlib.pyplot as plt import numpy as np #创建带数字标签的直方图 numbers = list(range(1,11)) #np.array()将列表转换为存储单一数据类型的多维数组 x = np.array(numbers) y = np.array([a**2 for a in numbers]) plt.bar(x,y,width=0.5,align=\'center\',color=\'c\') plt.title(\'Square Numbers\',fontsize=24) plt.xlabel(\'Value\',fontsize=14) plt.ylabel(\'Square of Value\',fontsize=14) plt.tick_params(axis=\'both\',labelsize=14) plt.axis([0,11,0,110]) for a,b in zip(x,y): plt.text(a,b+0.1,\'%.0f\'%b,ha = \'center\',va = \'bottom\',fontsize=7) plt.savefig(\'images\squares.png\') plt.show()
#模块pyplot包含很多生成图表的函数 import matplotlib.pyplot as plt import numpy as np input_values = [1,2,3,4,5,6] squares = [1,4,9,16,25,36] #plot()绘制折线图 plt.plot(input_values,squares,linewidth=5) #np.array()将列表转换为存储单一数据类型的多维数组 x = np.array(input_values) y = np.array(squares) #annotate()给折线点设置坐标值 for a,b in zip(x,y): plt.annotate(\'(%s,%s)\'%(a,b),xy=(a,b),xytext=(-20,10), textcoords=\'offset points\') #设置标题 plt.title(\'Square Numbers\',fontsize=24) plt.xlabel(\'Value\',fontsize=14) plt.ylabel(\'Square of Value\',fontsize=14) #设置刻度的大小,both代表xy同时设置 plt.tick_params(axis=\'both\',labelsize=14) #show()打开matplotlib查看器,并显示绘制的图形 plt.show()