python 折线图 点_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')

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值