300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > matplotlib 散点图_python之matplotlib 折线图和散点图

matplotlib 散点图_python之matplotlib 折线图和散点图

时间:2020-12-14 06:36:17

相关推荐

matplotlib 散点图_python之matplotlib 折线图和散点图

安装完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')

代码较简单,运行结果如下

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。