安装完python,接下来学习数据分析。找了篇教程学习matplotlib,写折线图和散点图。
首先pip install matplotlib安装。
输入代码:
import matplotlib.pyplot as plt
input_values =[1,2,3,4,5]
squares = [1,4,9,16,25]
#plt.plot(squares,linewidth=5)
plt.plot(input_values,squares,linewidth=5)#绘制折线图,使用plot接收数据
plt.title("squares Numbers",fontsize=24)
plt.xlabel("Value",fontsize=24)#x坐标
plt.ylabel('Squares Value',fontsize=14)#y坐标
plt.tick_params(axis='both',labelsize=12)
plt.show()
x_values = list(range(1,101))
y_values = [x**2 for x in x_values]
plt.scatter(x_values,y_values,c=y_values,cmap=plt.cm.Blues,edgecolors="none",s=40)#绘制散点图,使用scatter接收数据
plt.title("squares Numbers",fontsize=24)
plt.xlabel("Value",fontsize=14)
plt.ylabel('Squares Value',fontsize=14)
plt.tick_params(axis='both',labelsize=12)
plt.axis([0,110,0,11000])
plt.show()
plt.savefig('squares_plot.png', bbox_inches='tight')
代码较简单,运行结果如下