Python数据可视化之画图
2019/7/14 23:43:44
本文主要是介绍Python数据可视化之画图,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
安装数据可视化模块matplotlib:pip install matplotlib
导入matplotlib模块下的pyplot
1 折线图
from matplotlib import pyplot #横坐标 year=[2010,2012,2014,2016] #纵坐标 perple=[20,40,60,100] #生成折线图:函数polt pyplot.plot(year,perple) #设置横坐标说明 pyplot.xlabel('year') #设置纵坐标说明 pyplot.ylabel('population') #添加标题 pyplot.title('Population year correspondence') #设置纵坐标刻度 pyplot.yticks([0, 25, 50, 75, 90]) # 显示网格 pyplot.grid(True) 显示图表 pyplot.show()
2 散点图
用两种方法
第一种:只需将函数polt换成scatter即可.
from matplotlib import pyplot #横坐标 year=[2010,2012,2014,2016] #纵坐标 perple=[20,40,60,100] #生成散点图:函数scatter pyplot.scatter(year,perple) #设置横坐标说明 pyplot.xlabel('year') #设置纵坐标说明 pyplot.ylabel('population') #添加标题 pyplot.title('Population year correspondence') #设置纵坐标刻度 pyplot.yticks([0, 25, 50, 75, 90]) # 显示网格 pyplot.grid(True) 显示图表 pyplot.show()
第二种方法:在polt函数里添加第三个参数 “o”.
可以更改点的颜色和类型,如红色,五角型:把plot第三个参数改为'rp'.
#点的颜色
- c–cyan–青色
- r–red–红色
- m–magente–品红
- g–green–绿色
- b–blue–蓝色
- y–yellow–黄色
- k–black–黑色
- w–white–白色
#线的类型
- – 虚线
- -. 形式即为-.
- : 细小的虚线
#点的类型
- s–方形
- h–六角形
- H–六角形
- *–*形
- ±-加号
- x–x形
- d–菱形
- D–菱形
- p–五角形
from matplotlib import pyplot #横坐标 year=[2010,2012,2014,2016] #纵坐标 perple=[20,40,60,100] #生成散点图:函数polt pyplot.plot(year,perple,'rp') #设置横坐标说明 pyplot.xlabel('year') #设置纵坐标说明 pyplot.ylabel('population') #添加标题 pyplot.title('Population year correspondence') #设置纵坐标刻度 pyplot.yticks([0, 25, 50, 75, 90]) # 显示网格 pyplot.grid(True) 显示图表 pyplot.show()
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对找一找教程网的支持。如果你想了解更多相关内容请查看下面相关链接
这篇关于Python数据可视化之画图的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python